Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recieve POST data sent using "application/octet-stream" in PHP?

Here's what I'm dealing with. One of our programs has a support form that users use to request support. What this form does is, it performs an HTTP POST request to a PHP script that's supposed to collect the info and forward it to the support e-mail address.

The POST request contains three text fields of the type Content-Type: text/plain which can be easily read in PHP using $_POST['fieldname']. Some of the content in this POST request, however, are files, of type Content-Type: application/octet-stream. Using $_POST doesn't seem to work with these files. How do I go about reading the contents of these files?

Thank you in advance.

like image 795
Jimmy Avatar asked Dec 06 '10 18:12

Jimmy


1 Answers

You have to use the $_FILES superglobal:

$contents = file_get_contents($_FILES['myfile']['tmp_name']);

You can find more information in the manual. This will only work if you are using multipart/form-data encoding in your request.

You can otherwise read the raw POST data, then parse it yourself:

$rawPost = file_get_contents('php://input');
like image 118
netcoder Avatar answered Nov 10 '22 09:11

netcoder