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

Here is what I mean. One of our programs has a support form that users use to request support. What this form does is it executes an HTTP POST request for a PHP script that should collect information and forward it to the support email address.

The POST request contains three text fields of type Content-Type: text/plain , which can be easily read in PHP using $_POST['fieldname'] . However, some of the contents of this POST request are files of type Content-Type: application/octet-stream . Using $_POST does not seem to work with these files. How can I read the contents of these files?

Thanks in advance.

+4
source share
3 answers

You must use the super _ $ FILES:

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

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

Otherwise, you can read the raw POST data and then analyze it yourself:

 $rawPost = file_get_contents('php://input'); 
+9
source

Use the $ _FILES array.

0
source

Those under the super-switch $ _FILES. Read about it here: http://php.net/manual/en/features.file-upload.php

Basically, you get an array that looks like a POST, but with things like file size, temporary name and temporary file location, which you can use to check and move the file to a permanent location.

Additional general information from the PHP manual: http://php.net/manual/en/features.file-upload.php

-1
source

All Articles