Note that there are some explanatory texts on larger screens.

plurals
  1. POuploaded file is not same as the original was
    text
    copied!<p>i have a code that will upload a file on to a server. for testing purpose i create a local server(localhost) onto my PC by using Apache. my program is making/uploading file with the same name as of original file but its content is copied. in my program i used this line "file contents are here" for debugging purpose , and its the only line which is written in the uploaded file. i used a PHP script that will accept the file and upload it to the specified location. now i am confused that is it PHP's Problem or whether it is in my code. here is my code snipt :-</p> <pre><code>static TCHAR frmdata[] = "-----------------------------7d82751e2bc0858\r\nContent-Disposition: form-data; name=\"uploadedfile\"; filename=\"D:\\er.txt\"\r\nContent-Type: text/plain\r\n\r\nfile contents here\r\n-----------------------------7d82751e2bc0858--\r\n"; static TCHAR hdrs[] = "Content-Type: multipart/form-data; boundary=---------------------------7d82751e2bc0858"; HINTERNET hSession = InternetOpen("MyBrowser",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); if(!hSession) { cout&lt;&lt;"Error: InternetOpen"; } HINTERNET hConnect = InternetConnect(hSession, _T("localhost"),INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1); if(!hConnect) { cout&lt;&lt;"Error: InternetConnect"; } //HINTERNET hRequest = HttpOpenRequest(hConnect, (const char*)"POST",_T("upload.php"), NULL, NULL, (const char**)"*/*\0", 0, 1); LPCTSTR rgpszAcceptTypes[] = {_T("*/*"), NULL}; HINTERNET hRequest = HttpOpenRequest(hConnect, (const char*)"POST", _T("upload.php"), NULL, NULL, rgpszAcceptTypes, 0, 1); if(hRequest==NULL) { cout&lt;&lt;"Error: HttpOpenRequest"; } BOOL sent= HttpSendRequest(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata)); if(!sent) { cout&lt;&lt;"Error: HttpSendRequest "&lt;&lt;GetLastError(); } char buffer[2048] = {}; DWORD bufferSize = sizeof(buffer); BOOL success = HttpQueryInfo(hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, buffer, &amp;bufferSize, NULL); if(!success) { std::cout&lt;&lt;"Error: HttpQueryInfo "&lt;&lt; GetLastError(); return 0; } std::cout &lt;&lt; buffer &lt;&lt; std::endl; ZeroMemory(buffer, sizeof(buffer)); success = InternetReadFile(hRequest, buffer, sizeof(buffer), &amp;bufferSize); if(!success) { std::cout &lt;&lt; "Error: InternetReadFile " &lt;&lt; GetLastError(); return 0; } std::cout &lt;&lt; buffer &lt;&lt; std::endl; //close any valid internet-handles InternetCloseHandle(hSession); InternetCloseHandle(hConnect); InternetCloseHandle(hRequest); getchar(); </code></pre> <p>here is PHP script:-</p> <pre><code>if (is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) { $uploadfile = $uploaddir . basename($_FILES['uploadedfile']['name']); echo "File ". $_FILES['uploadedfile']['name'] ." uploaded successfully. "; if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully moved. "; } else print_r($_FILES); } else { echo "Upload Failed!!!"; print_r($_FILES); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload