How to send a file via curl function in php?
1 answer
To upload a file that's on your server, yes curl can do the trick.
You want to use the option by passing it (quoting): CURLOPT_POSTFIELDS
curl_setopt
Complete data to publish in HTTP "POST" operation.
To publish the file, add the file name with@
and use the full path.
Untested, but I suppose something like this should work:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.yoursite.com/destination-of-upload.php");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setpopt($ch, CURLOPT_POSTFIELDS, array(
'file' => '@/..../some-file.txt', // you'll need to adapt this
// some other fields ?
));
$result = curl_exec($ch);
curl_close($ch);
+4
source to share