ARG! How do you pass parameters AND a file in HTTP POST?
Posted: Fri Nov 19, 2010 4:18 pm
Hi all.
This seems to be an oft-asked but never clearly answered question on the Web. I'm sending files to a PHP upload page using HTTP post from C++, and I also want to send the name of the directory I want the file stored in. I don't know where to put that directory-name string in the POST message, nor do I know how to retrieve it using PHP at the receiving end. The upload is working fine, but I admit I don't understand the syntax of the PHP page that's doing the receiving.
The POST request is pieced together line by line, as I found done in various examples. Like this:
One post suggested that you could add another Content-Disposition line to create another form field for an additional parameter, but this broke the form as far as PHP was concerned.
Primarily I just need to get this working, but I also don't understand where all of the $_FILES info comes from at the PHP receiving end. For example, the POST snippet above clearly contains a value called "filename", but there is no reference to "filename" anywhere in the PHP upload page. Yet it works.
Any insight would be much appreciated!
This seems to be an oft-asked but never clearly answered question on the Web. I'm sending files to a PHP upload page using HTTP post from C++, and I also want to send the name of the directory I want the file stored in. I don't know where to put that directory-name string in the POST message, nor do I know how to retrieve it using PHP at the receiving end. The upload is working fine, but I admit I don't understand the syntax of the PHP page that's doing the receiving.
The POST request is pieced together line by line, as I found done in various examples. Like this:
Code: Select all
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%s\"\r\n",
filename.c_str()] dataUsingEncoding:NSUTF8StringEncoding]];
Primarily I just need to get this working, but I also don't understand where all of the $_FILES info comes from at the PHP receiving end. For example, the POST snippet above clearly contains a value called "filename", but there is no reference to "filename" anywhere in the PHP upload page. Yet it works.
Any insight would be much appreciated!