Rovin Patwal
Rovin Patwal

Reputation: 119

Extract form-data PHP

Can someone tell me how to get the data from post request body(form-data)? This is how I am calling the API using Postman: enter image description here

I am printing the input using below code:

$data = file_get_contents('php://input');
echo $data;

This is the output that I get:

------WebKitFormBoundarycHQ9xxbmOdQAcZNF
Content-Disposition: form-data; name="testFile"; filename="abc.csv"
Content-Type: application/vnd.ms-excel

Name,Value
test,QA
contact,789789
------WebKitFormBoundarycHQ9xxbmOdQAcZNF
Content-Disposition: form-data; name="testData"

['aa','bbbb']
------WebKitFormBoundarycHQ9xxbmOdQAcZNF
Content-Disposition: form-data; name="testBool"

true
------WebKitFormBoundarycHQ9xxbmOdQAcZNF--

How can extract the csv data, testData array, and testBool value from the form-data?

Upvotes: 0

Views: 2004

Answers (1)

Quentin
Quentin

Reputation: 944020

Don't try to do this manually. Ignore php://input read the data from the $_POST and $_FILES superglobals. The data comes preparsed there.

Upvotes: 1

Related Questions