I’m trying to POST a file in a multipart message. The problem is that I need to pass two extra parameters with that file. And I want them to be accessible in POST parameters array. The question is whether is possible to add part to multipart message so that it’ll be interpreted as POST parameter? Or am I wasting time?
I want that e.g:
--1BEF0A57BE110FD467A\r\n
Content-Disposition: form-data; name="name1"\r\n
\r\n
value\r\n
be accsessible with $_POST['name1']
PS: as far as I know, if one uploads file with actionscript FileReference.upload(urlRequest) and specifies post params in urlRequest then they’ll be in $_POST
What you want to do is in fact exactly the way that multipart messages work in relation to the
$_POSTarray.Consider the following HTML form:
Now lets say we populate the three text inputs with
value1,value2andvalue3, we select a file calledfile.txt, and press submit. This will result in a request that looks something like this:When we look at it in PHP, if we
print_r($_POST);we should get something like this:…and if we
print_r($_FILES);:…so you can see, the parts of the message where the
Content-Disposition:header does not contain afilename=""element are added to the$_POSTarray, and those with one are treated as file uploads and added to$_FILES.When building a
multipart/form-datamessage to send to a server, I find it easiest to build the HTML form that you are mimicking with the request, and construct your HTTP message based on how that HTML form would behave.