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 -
hFileXfer = InternetOpen("FileSession", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
-
if(hFileXfer != 0)
-
hConnect = InternetConnect(hFileXfer, "localhost", 80, "", "", INTERNET_SERVICE_HTTP, 0,0);
-
if(hConnect != 0)
-
{
-
DWORD flags;
-
flags = INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_PRAGMA_NOCACHE;
-
hReq = HttpOpenRequest(hConnect,"POST", "./TargetDir/ClientUpload.php", NULL, NULL, NULL, flags, 0);
-
if(hReq != 0)
-
{
-
if(HttpSendRequestEx(hReq, NULL, NULL,0, NULL))
-
{
-
do
-
{
-
if(bRead = (bool)ReadFile(hSrcFile,&pBuffer, sizeof(pBuffer), &dwBytesRead, NULL))
-
{
-
if(!(bRtn =(bool)InternetWriteFile(hReq, pBuffer, dwBytesRead, &dwBytesWritten)))
-
{
-
DWORD DwError = GetLastError();
-
*ErrStr = "Unable to write file to server";
-
break;
-
}
-
dwTotalWritten += dwBytesWritten;
-
}
-
else
-
{
-
DWORD DwError = GetLastError();
-
*ErrStr = "Error reading source file";
-
bRtn = false;
-
break;
-
}
-
} while(dwTotalWritten < dwFileSize);
-
CloseHandle(hSrcFile);
-
TCHAR RtnBuffer[1000];
-
DWORD ret;
-
bRtn = InternetReadFile(hReq, RtnBuffer, 1000, &ret);
-
InternetCloseHandle(hReq);
-
InternetCloseHandle(hConnect);
-
InternetCloseHandle(hFileXfer);
-
}
-
}
-
}
-
}
PHP code -
<?php
-
$uploaddir = '/TargetDir/ClientUploads/';
-
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
-
-
echo '<pre>';
-
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
-
echo "File is valid, and was successfully uploaded.\n";
-
} else {
-
echo "Possible file upload attack!\n";
-
}
-
-
echo 'Here is some more debugging info:';
-
print_r($_FILES);
-
-
print "</pre>";
-
-
?>
7 3537
What output do you get? Any PHP errors?
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
Unfortunately I am out of ideas for this :/
I know squat about C++.
Maybe someone else will be able to help.
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 -
$connection = mysql_connect('localhost','root',''); // or die('Error: ' . mysql_error());
-
if(!$connection)
-
$StatusStr = 'DatabaseError';
-
else
-
{
-
mysql_select_db("watchdog", $connection);
-
$sql = "INSERT INTO testTbl ( TestSeen) VALUES ( '1')";
-
$Result = mysql_query($sql);
-
}
-
$uploaddir = 'ClientUploads/';
-
if(empty($_FILES["uploaded_file"]))
-
{
-
$sql = "INSERT INTO testTbl ( TestSeen) VALUES ( 'EMPTY')";
-
$Result = mysql_query($sql);
-
}
-
In the table I see 1 followed by EMPTY
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?
NOPE.
This should work.
I get no errors on the C++ side.
If there is no data in the FILES array, then your C++ application is not submitting the data correctly.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
by: Rob Nicholson |
last post by:
The following code added to Page_Load works a treat:
Response.ContentType = "application/zip"
Response.AppendHeader("Content-Disposition",...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...
| |