Click here to Skip to main content
15,793,260 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: C: Book recommendations Pin
Richard Andrew x645-Oct-15 13:09
professionalRichard Andrew x645-Oct-15 13:09 
GeneralRe: C: Book recommendations Pin
Albert Holguin6-Oct-15 5:59
professionalAlbert Holguin6-Oct-15 5:59 
QuestionWindows message for changing color scheme Pin
_Flaviu5-Oct-15 3:15
_Flaviu5-Oct-15 3:15 
AnswerRe: Windows message for changing color scheme Pin
_Flaviu5-Oct-15 4:07
_Flaviu5-Oct-15 4:07 
QuestionRe: Windows message for changing color scheme Pin
Richard MacCutchan5-Oct-15 4:47
mveRichard MacCutchan5-Oct-15 4:47 
AnswerRe: Windows message for changing color scheme Pin
_Flaviu5-Oct-15 21:18
_Flaviu5-Oct-15 21:18 
AnswerRe: Windows message for changing color scheme Pin
_Flaviu7-Oct-15 1:46
_Flaviu7-Oct-15 1:46 
Questionuploadig adobe reader file in local host in c language Pin
sunycity4-Oct-15 23:31
sunycity4-Oct-15 23:31 
> I am uploading adobe files in local host it is uploading file successfully but it is showing corrupt or damage file after opening file please help me out to sort out this problem i will be thankful to you below is my entire code



int main()
{
static char *filename = "tutorial.pdf"; //Filename to be loaded
static char *filepath = "C:\\tutorial.pdf"; //Filename to be loaded

`static char *type = "text/pdf";`

static TCHAR hdrs[] = "Content-Type: multipart/form-data; boundary=---------------------------7d82751e2bc0858";
static char boundary[] = "-----------------------------7d82751e2bc0858"; //Header boundary
static char nameForm[] = "uploadedfile"; //Input form name
static char iaddr[] = "localhost"; //IP address
static char url[] = "/xampp/testing/upload.php?folder=aaaa&&foldername=bbbb";

char * buffer; //Buffer containing file + headers
char * content; //Buffer containing file
FILE * pFile; //File pointer
long lSize; //File size
size_t result;
char *pos; // used in the loop

// Open file
pFile = fopen(filepath, "rb");
if (pFile == NULL)
{
printf("ERROR_OPEN_FILE");
getchar();
return ERROR_OPEN_FILE;
}
printf("OPEN_FILE\n");

// obtain file size:
fseek(pFile, 0, SEEK_END);
lSize = ftell(pFile);
rewind(pFile);

// allocate memory to contain the whole file:
content = (char*)malloc(sizeof(char)*lSize);
if (content == NULL)
{
printf("ERROR_MEMORY");
getchar();
return ERROR_OPEN_FILE;
}
printf("MEMORY_ALLOCATED\t \"%d\" \n", lSize);
// copy the file into the buffer:
result = fread(content, 1, lSize, pFile);

rewind (pFile);

if (result != lSize)
{
printf("ERROR_SIZE");
getchar();
return ERROR_OPEN_FILE;
}
printf("SIZE_OK\n");

// terminate
fclose(pFile);
printf("FILE_CLOSE\n");
//allocate memory to contain the whole file + HEADER
buffer = (char*)malloc(sizeof(char)*lSize + 2048);

//print header
sprintf(buffer, "%s\r\nContent-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\n", boundary, nameForm, filename);
sprintf(buffer, "%sContent-Type: %s\r\n", buffer, type);
sprintf(buffer, "%sContent-Length: %d\r\n", buffer, lSize);



sprintf(buffer, "%s\r\n", buffer);
memcpy(buffer + strlen(buffer),content,lSize);
sprintf(buffer, "%s\r\n", buffer);

sprintf(buffer, "%s%s--\r\n", buffer, boundary);

//Open internet connection
HINTERNET hSession = InternetOpen("WINDOWS", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (hSession == NULL)
{
printf("ERROR_INTERNET_OPEN");
getchar();
return ERROR_OPEN_FILE;
}
printf("INTERNET_OPENED\n");

HINTERNET hConnect = InternetConnect(hSession, iaddr, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
if (hConnect == NULL)
{
printf("ERROR_INTERNET_CONN");
getchar();
return ERROR_INTERNET_CONN;
}
printf("INTERNET_CONNECTED\n");

HINTERNET hRequest = HttpOpenRequest(hConnect, (const char*)"POST", _T(url), NULL, NULL, NULL, INTERNET_FLAG_RELOAD, 1);
if (hRequest == NULL)
{
printf("ERROR_INTERNET_REQ");
getchar();

}
printf("INTERNET_REQ_OPEN\n");

BOOL sent = HttpSendRequest(hRequest, hdrs, strlen(hdrs), buffer, strlen(buffer));

if (!sent)
{
printf("ERROR_INTERNET_SEND");
getchar();
return ERROR_INTERNET_CONN;
}
printf("INTERNET_SEND_OK\n");
printf("\r\n%s\r\n",buffer);

//close any valid internet-handles
InternetCloseHandle(hSession);
InternetCloseHandle(hConnect);
InternetCloseHandle(hRequest);
getch();
return 0;

}
AnswerRe: uploadig adobe reader file in local host in c language Pin
Jochen Arndt4-Oct-15 23:54
professionalJochen Arndt4-Oct-15 23:54 
QuestionCFileDialog OnTypeChange issue Pin
_Flaviu1-Oct-15 21:59
_Flaviu1-Oct-15 21:59 
QuestionRe: CFileDialog OnTypeChange issue Pin
_Flaviu2-Oct-15 4:00
_Flaviu2-Oct-15 4:00 
AnswerRe: CFileDialog OnTypeChange issue Pin
Maximilien2-Oct-15 5:06
Maximilien2-Oct-15 5:06 
GeneralRe: CFileDialog OnTypeChange issue Pin
_Flaviu4-Oct-15 22:29
_Flaviu4-Oct-15 22:29 
QuestionA c program to project expected number of rabbits on a farm Pin
Arnold Mukisa29-Sep-15 9:27
Arnold Mukisa29-Sep-15 9:27 
AnswerRe: A c program to project expected number of rabbits on a farm Pin
Arnold Mukisa29-Sep-15 9:30
Arnold Mukisa29-Sep-15 9:30 
SuggestionRe: A c program to project expected number of rabbits on a farm Pin
David Crow29-Sep-15 16:42
David Crow29-Sep-15 16:42 
GeneralRe: A c program to project expected number of rabbits on a farm Pin
David Crow29-Sep-15 16:34
David Crow29-Sep-15 16:34 
QuestionRe: A c program to project expected number of rabbits on a farm Pin
Paul Conrad1-Oct-15 8:33
professionalPaul Conrad1-Oct-15 8:33 
GeneralRe: A c program to project expected number of rabbits on a farm Pin
David Crow1-Oct-15 11:19
David Crow1-Oct-15 11:19 
Question0 bytes CImage saved Pin
_Flaviu29-Sep-15 0:47
_Flaviu29-Sep-15 0:47 
QuestionRe: 0 bytes CImage saved Pin
CPallini29-Sep-15 1:02
mveCPallini29-Sep-15 1:02 
AnswerRe: 0 bytes CImage saved Pin
_Flaviu29-Sep-15 1:06
_Flaviu29-Sep-15 1:06 
AnswerRe: 0 bytes CImage saved Pin
_Flaviu29-Sep-15 1:33
_Flaviu29-Sep-15 1:33 
SuggestionRe: 0 bytes CImage saved Pin
Jochen Arndt29-Sep-15 1:36
professionalJochen Arndt29-Sep-15 1:36 
GeneralRe: 0 bytes CImage saved Pin
_Flaviu29-Sep-15 1:57
_Flaviu29-Sep-15 1:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.