'm having issues transferring a file from a WEB client running a C++ application to a PHP server script. I have debugged through the C++ side and no errors are reported, but the file does not appear on the server. My current environment is a Vista business system running IIS. I developed the C++ app using Microsoft's Visual Studio. I know the configuration is correct as the application does communicate with PHP scripts to transfer XML data back and forth. I cannot seem to get the file upload to work. I have attached both the C++ and PHP sides. Any assistance would be greatly appreciated.
C++ code
Expand|Select|W rap|Line Numbers
PHP code
Expand|Select|W rap|Line Numbers
C++ code
Expand|Select|W rap|Line Numbers
Code:
1. hFileXfer = InternetOpen("FileSession", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2. if(hFileXfer != 0)
3. hConnect = InternetConnect(hFileXfer, "localhost", 80, "", "", INTERNET_SERVICE_HTTP, 0,0);
4. if(hConnect != 0)
5. {
6. DWORD flags;
7. flags = INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_PRAGMA_NOCACHE;
8. hReq = HttpOpenRequest(hConnect,"POST", "./TargetDir/ClientUpload.php", NULL, NULL, NULL, flags, 0);
9. if(hReq != 0)
10. {
11. if(HttpSendRequestEx(hReq, NULL, NULL,0, NULL))
12. {
13. do
14. {
15. if(bRead = (bool)ReadFile(hSrcFile,&pBuffer, sizeof(pBuffer), &dwBytesRead, NULL))
16. {
17. if(!(bRtn =(bool)InternetWriteFile(hReq, pBuffer, dwBytesRead, &dwBytesWritten)))
18. {
19. DWORD DwError = GetLastError();
20. *ErrStr = "Unable to write file to server";
21. break;
22. }
23. dwTotalWritten += dwBytesWritten;
24. }
25. else
26. {
27. DWORD DwError = GetLastError();
28. *ErrStr = "Error reading source file";
29. bRtn = false;
30. break;
31. }
32. } while(dwTotalWritten < dwFileSize);
33. CloseHandle(hSrcFile);
34. TCHAR RtnBuffer[1000];
35. DWORD ret;
36. bRtn = InternetReadFile(hReq, RtnBuffer, 1000, &ret);
37. InternetCloseHandle(hReq);
38. InternetCloseHandle(hConnect);
39. InternetCloseHandle(hFileXfer);
40. }
41. }
42. }
43. }
Expand|Select|W rap|Line Numbers
Code:
1. <?php
2. $uploaddir = '/TargetDir/ClientUploads/';
3. $uploadfile = $uploaddir . basename($_FILES['file']['name']);
4.
5. echo '<pre>';
6. if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
7. echo "File is valid, and was successfully uploaded.\n";
8. } else {
9. echo "Possible file upload attack!\n";
10. }
11.
12. echo 'Here is some more debugging info:';
13. print_r($_FILES);
14.
15. print "</pre>";
16.
17. ?>
Comment