Click here to Skip to main content
14,549,035 members

C / C++ / MFC

 
AnswerRe: C: Book recommendations Pin
Richard Andrew x645-Oct-15 12:09
professionalRichard Andrew x645-Oct-15 12:09 
GeneralRe: C: Book recommendations Pin
Albert Holguin6-Oct-15 4:59
professionalAlbert Holguin6-Oct-15 4:59 
QuestionWindows message for changing color scheme Pin
_Flaviu5-Oct-15 2:15
Member_Flaviu5-Oct-15 2:15 
AnswerRe: Windows message for changing color scheme Pin
_Flaviu5-Oct-15 3:07
Member_Flaviu5-Oct-15 3:07 
QuestionRe: Windows message for changing color scheme Pin
Richard MacCutchan5-Oct-15 3:47
mveRichard MacCutchan5-Oct-15 3:47 
AnswerRe: Windows message for changing color scheme Pin
_Flaviu5-Oct-15 20:18
Member_Flaviu5-Oct-15 20:18 
AnswerRe: Windows message for changing color scheme Pin
_Flaviu7-Oct-15 0:46
Member_Flaviu7-Oct-15 0:46 
Questionuploadig adobe reader file in local host in c language Pin
sunycity4-Oct-15 22:31
Membersunycity4-Oct-15 22: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 22:54
professionalJochen Arndt4-Oct-15 22:54 
QuestionCFileDialog OnTypeChange issue Pin
_Flaviu1-Oct-15 20:59
Member_Flaviu1-Oct-15 20:59 
QuestionRe: CFileDialog OnTypeChange issue Pin
_Flaviu2-Oct-15 3:00
Member_Flaviu2-Oct-15 3:00 
AnswerRe: CFileDialog OnTypeChange issue Pin
Maximilien2-Oct-15 4:06
MemberMaximilien2-Oct-15 4:06 
GeneralRe: CFileDialog OnTypeChange issue Pin
_Flaviu4-Oct-15 21:29
Member_Flaviu4-Oct-15 21:29 
QuestionA c program to project expected number of rabbits on a farm Pin
Arnold Mukisa29-Sep-15 8:27
MemberArnold Mukisa29-Sep-15 8:27 
AnswerRe: A c program to project expected number of rabbits on a farm Pin
Arnold Mukisa29-Sep-15 8:30
MemberArnold Mukisa29-Sep-15 8:30 
SuggestionRe: A c program to project expected number of rabbits on a farm Pin
David Crow29-Sep-15 15:42
MemberDavid Crow29-Sep-15 15:42 
GeneralRe: A c program to project expected number of rabbits on a farm Pin
David Crow29-Sep-15 15:34
MemberDavid Crow29-Sep-15 15:34 
QuestionRe: A c program to project expected number of rabbits on a farm Pin
Paul Conrad1-Oct-15 7:33
subeditorPaul Conrad1-Oct-15 7:33 
GeneralRe: A c program to project expected number of rabbits on a farm Pin
David Crow1-Oct-15 10:19
MemberDavid Crow1-Oct-15 10:19 
Question0 bytes CImage saved Pin
_Flaviu28-Sep-15 23:47
Member_Flaviu28-Sep-15 23:47 
QuestionRe: 0 bytes CImage saved Pin
CPallini29-Sep-15 0:02
mveCPallini29-Sep-15 0:02 
AnswerRe: 0 bytes CImage saved Pin
_Flaviu29-Sep-15 0:06
Member_Flaviu29-Sep-15 0:06 
AnswerRe: 0 bytes CImage saved Pin
_Flaviu29-Sep-15 0:33
Member_Flaviu29-Sep-15 0:33 
SuggestionRe: 0 bytes CImage saved Pin
Jochen Arndt29-Sep-15 0:36
professionalJochen Arndt29-Sep-15 0:36 
GeneralRe: 0 bytes CImage saved Pin
_Flaviu29-Sep-15 0:57
Member_Flaviu29-Sep-15 0: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.