473,734 Members | 2,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ client upload to PHP server

7 New Member
I'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|Wrap|Line Numbers
  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. }

PHP code
Expand|Select|Wrap|Line Numbers
  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. ?>
Apr 21 '09 #1
7 3633
Markus
6,050 Recognized Expert Expert
What output do you get? Any PHP errors?
Apr 21 '09 #2
wwhitman
7 New Member
Appears I get nothing from PHP side. I am not even sure it gets activated. I think I remember putting in some code on the PHP to write to an MySQL Db and nothing appeared, and it was the first thing I did
Apr 21 '09 #3
Markus
6,050 Recognized Expert Expert
Unfortunately I am out of ideas for this :/
I know squat about C++.

Maybe someone else will be able to help.
Apr 21 '09 #4
wwhitman
7 New Member
UPDATE: I think I got the C++ side working. I can go through the code and no errors are reported. The PHP script gets executed but there is no file there
Expand|Select|Wrap|Line Numbers
  1. $connection = mysql_connect('localhost','root',''); // or die('Error: ' . mysql_error()); 
  2. if(!$connection)
  3.    $StatusStr = 'DatabaseError';
  4. else
  5. {
  6.    mysql_select_db("watchdog", $connection);
  7.    $sql = "INSERT INTO testTbl ( TestSeen) VALUES ( '1')";
  8.    $Result = mysql_query($sql);
  9. }
  10. $uploaddir = 'ClientUploads/';
  11. if(empty($_FILES["uploaded_file"]))
  12. {
  13.     $sql = "INSERT INTO testTbl ( TestSeen) VALUES ( 'EMPTY')";
  14.     $Result = mysql_query($sql);
  15. }
  16.  
In the table I see 1 followed by EMPTY
Apr 22 '09 #5
Markus
6,050 Recognized Expert Expert
I'm not sure you're able to send a file like that and have PHP recognise it. Does C++ have access to a cURL library?
Apr 22 '09 #6
wwhitman
7 New Member
NOPE.
This should work.
I get no errors on the C++ side.
Apr 22 '09 #7
Markus
6,050 Recognized Expert Expert
If there is no data in the FILES array, then your C++ application is not submitting the data correctly.
Apr 22 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2896
by: WM Chung | last post by:
Hello all, My dotnet application configuration is that the client, Web server and database all reside in 3 different computers. There is a function which can browse a file and read in the contents. When it is run by Internet explorer in the client machine, it can browse the file path in the client machine. However, when the program attempt to read in the file content, there is run time error. I suspect the program try to read the file in...
1
3154
by: alfredfx | last post by:
i'm planning to develop a client server system the client and server both able to upload picture client will upload the picture to a folder that reside in the server while server user can also upload picture to that folder also and then client and server can retrieve the picture from there. can someone giv some guide to me how to work this out ? i'v been lookin for solution. 1. using sqldatabase to store picture 2. ....
6
1792
by: jake | last post by:
How do you get or save a file from/to a client (button on web page) once they are authenticated? The client could be Mac, Linux or Windows. Can I do it all with IIS and ASP.NET?
3
1745
by: Rob Nicholson | last post by:
The following code added to Page_Load works a treat: Response.ContentType = "application/zip" Response.AppendHeader("Content-Disposition", "attachment; filename=DesktopChange.pdf") Response.WriteFile("C:\Inetpub\wwwroot\Download\DesktopChange.pdf") Response.Flush() But *only* if the document exists in the web site or is accessible by the ASPNET account. However, it fails if the document is stored on the network,
9
2415
by: CGW | last post by:
I asked the question yesterday, but know better how to ask it, today: I'm trying to use the File.Copy method to copy a file from a client to server (.Net web app under IIS ). It looks to me that when I give a path like @"C:\holdfiles\myfile.txt" it looks on the server C drive. How do I pull from the client? Do I need a different class and/or method? Filestream? -- Thanks,
6
9531
by: dinoo | last post by:
Hi, I would appreciate if some one could help me out. I have to read a client side ini file in Aspx page and use that data in server side processing. Can any one help me out here? Please refer to a link if possible. Thanks, Dinoo
10
2262
by: Paul | last post by:
Hi I am using the HtmlInputFile control to upload a file from a client to a server. I have a browse to find the file on the server but need to create the path dynamically as to were it will go based on some dropdown boxes, one for the year and one for the month. This line saves the file so I am trying to get the month and year from the dropdown boxes and put them in the month and year variables but this does not work,...
12
2906
by: SAL | last post by:
Hello, Is it possible to read a CSV from the Client, and bind my Datagrid to the data in the CSV file without uploading the file to the Server first? I have tried and in Debug mode on my workstation it works fine, but when I publish the page on our DEV server it doesn't fine the CSV file from the client. Has anyone done this before? If so, how do I do it? I'm new to ASP.net so
3
1159
by: pbd22 | last post by:
Hi There. I think i need some software design help. I have a page, server.aspx, that starts uploading video files when it is loaded via hidden iframe by the client. On the same page is an event handler (below) that produces useful data about the upload (percent, time, bytes, etc). MY PROBLEM is that the server.aspx file is being used for video
1
2089
by: SGilch | last post by:
I am new to javascript, and wondering if it is capable of implementing a browsing mechanism for the browser to upload the names of files in a client side directory to the server. The client would select a local directory through its web browser based on a page from the server and when hitting the submit button would upload a list of the files in the directory. So, I am looking for a way where the client can: - click a browse button on the...
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.