How to upload data to a php script ?

Posted on 2003-03-31
Medium Priority
Last Modified: 2012-06-27
Hello, i try to upload datas to a server that use a php script.
i have to post to "www.adress.com/fichier.php"

the script verify the datas, it should be formated as L=jean&P=dupont&Content=filadatas.
filedata should be binaries datas...

i' v tryed many solution but can get it work!

BYTE* pBuffer1 = new BYTE[(UINT)ulSourceFileSize];
pOrderFile->Read(pBuffer1, (UINT)ulSourceFileSize);

static TCHAR hdrs[] = _T("Content-Type: multipart/form-data");

HINTERNET hSession = ::InternetOpen("VPS",
                                   0) ;

HINTERNET hConnect = ::InternetConnect(hSession,
                                   0) ;

HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", "/monscript.php", NULL, NULL, 0, 0, 1);
TCHAR* cb = new TCHAR[ss.GetLength()];
::strcpy(cb, ss);

if (HttpSendRequest(hRequest, hdrs, strlen(hdrs), pBuffer1, (DWORD)pBuffer1.GetLength()))
   int i = 0; // i always pass here but nothing happen on server

So my question is : How can i get it work ? why if i pass a correct string with all the data (exept fila data) in IE it work,
and how to have the respnse of the server (the script respond like "transaction failes or transaction ok)?

thanks in advance...

ps : how to accepts a response on xpert xchange ?
Question by:Gaiza
LVL 12

Accepted Solution

Salte earned 120 total points
ID: 8238284
When passing information from a web site to a CGI (java, php, or whatever) script you have three ways to do so.

1. Pass arguments in the URL. For the receiver this is the easiest way, you simply provide the arguments in the URL and the receiver reads them from an environment variable. A web browser using this method will typically send the parameters along with the URL to the web server which stuff them in an environment variable.

2. Make a <form> </form> tag with a method of POST and pass data in the body of the request. The receiver gets the contents by reading from standard in which the server connects to the process. The server might use pipes for this purpose and stuff the message into a pipe and then give the process the pipe as stdin.

3. Put data into a cookie and send along the cookie to the server program.

If you are not a web browser but a C++ program that connect to the web server you essentially have to emulate the web browser and do what it should do in these cases. Which method you use is determined by which method the web server expects. If the page expects the data in the URL you essentially have to do the same as what a web browser does when it see an URL with parameters. If the page expects data from a form you have to send the data in the body of the message. I am not sure how much structure there is on those data and how they are actually sent. If data is stuffed from an edit box on the web page (such as the box where I type this message), the data is somehow inserted into the web page, but because a typical form can contain many such fields I believe there is SOME structure to such messages. The name of the field and the data and the body essentially contain a list of such entries, so if you have an edit box named "foo" and a listbox named "bar" the data sent will contain the name "foo" and then the text of that edit box and then when that is over the name "bar" and then the text associated with the user's choice of that list box.

Obviously there must be some characters to indicate that the text start and where it ends etc.

I am not sure about the details here but I believe it is something like:


of course, for a multiline edit box a simple ; won't do so I believe there is some special syntax for those - since HTTP requests and responses are essentially MIME messages (similar to E-mail messages) I believe they use similar syntax as E-mail does.

Details around this is found in various RFCs.


Expert Comment

ID: 9566530
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: Salte

Please leave any comments here within the next seven days.


EE Cleanup Volunteer

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question