I am trying to make a file upload with additional parameters in terminal, I use the -F
param to combine all the parameters I need, here is what I got:
curl -H "Content-Type:multipart/form-data" -F "[email protected]" -F "videoExt=mp4" -F "videoSize=10230" -F "thumbExt=png" -F "thumb=IufIsduSii823" -F "id=8" http://test.dev/test.php
The problem is that on the handling side (test.php) the $_FILES array is empty.
Then I tried to make a simple html form that will post to the handler a file, and I tried to make the curl request with php_curl
. Here goes the code:
$postargs = [
'videoExt' => 'mp4',
'id' => 8,
'thumb' => 'IkJdfjiaskdkI*82',
'thumbExt' => 'png',
'videoSize' => '10240'
];
foreach ($_FILES as $param => $file) {
$postargs[$param] = '@' . $file['tmp_name'] . ';filename=' . $file['name'] . ';type=' . $file['type'];
}
$header = array("Content-type: multipart/form-data");
$ch = curl_init('http://localhost:8080');
curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch,CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch,CURLOPT_ENCODING,"");
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch,CURLOPT_POST,TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postargs);
curl_exec($ch);
curl_close($ch);
This script succesfully makes a curl request to the handler and the file is uploaded. Please advise what is the difference, and how can I achieve that in terminal.
Its work for me, try use
-i
option, eg.: