> 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);
S
sunycity
@sunycity