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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

765 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