Multipart file form upload with curl
Posted: Sun Jun 14, 2009 1:35 pm
Hi all, first of all i am new here and hope that i can learn/help php in this forum:)
Well my problem is this, i am coding an script with php and curl that submits a csv file, but the problem is that it doesnt works, i mean it submits the file but it takes no effect.
Basically i want to upload the file "name.csv" using curl.
I got the POST sintaxis with live HTTPD headers (firefox) to add it to my curl function, the sintaxis is something like this:
So my curl code is this one:
So thats all i can say, the curl does the post correctly, but without effects.
I wonder how could i submit the file name.csv(which is hosted on the same server) using curl.
Thanks!:)
Well my problem is this, i am coding an script with php and curl that submits a csv file, but the problem is that it doesnt works, i mean it submits the file but it takes no effect.
Basically i want to upload the file "name.csv" using curl.
I got the POST sintaxis with live HTTPD headers (firefox) to add it to my curl function, the sintaxis is something like this:
Code: Select all
POST file.php -----------------------------257941320228008
Content-Disposition: form-data; name="SETTINGS_FILE"; filename="name.csv"
Content-Type: text/csv
$CONTENT OF THE CSV FILE HERE
-----------------------------257941320228008
Content-Disposition: form-data; name="SubmitSettings"
Upload Settings File
-----------------------------257941320228008--Code: Select all
$cah = curl_init();
curl_setopt($cah, CURLOPT_RETURNTRANSFER,1);
curl_setopt($cah, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($cah, CURLOPT_URL,"http://url/file.php");
curl_setopt($cah, CURLOPT_POST, 1);
curl_setopt($cah, CURLOPT_POSTFIELDS, "-----------------------------257941320228008
Content-Disposition: form-data; name=".SETTINGS_FILE."; filename=".name.csv."
Content-Type: text/csv
$CONTENT OF THE CSV FILE HERE
-----------------------------257941320228008
Content-Disposition: form-data; name=".SubmitSettings."
Upload Settings File
-----------------------------257941320228008--");
$r = curl_exec ($cah);
curl_close ($cah);
unset($cah);
I wonder how could i submit the file name.csv(which is hosted on the same server) using curl.
Thanks!:)