upload a file to server without using a form?
We imagine that form;
<form action="http://api.blabla.com/huhu.php" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" />
<button type="submit">submit</button>
</form&g开发者_如何学Ct;
I want to upload files to this server without using the form which is above.
I tried this with php curl but I could not.
I want it because I have very large number of files to upload. And this should be automatic with cron jobs.
This is an example of file uploading with cURL you could start with:
$ch = curl_init('http://api.blabla.com/huhu.php');
curl_setopt_array($ch, array(
CURLOPT_POSTFIELDS => array(
'files[]' => '@/path/to/file',
),
));
if (false === ($res = curl_exec($ch))) {
die("Upload failed: " . curl_error($ch));
}
The string '@/path/to/file'
has a special meaning because it starts with an @
; the string that directly follows it should contain the path of a file you wish to upload.
精彩评论