note 121971 added to class.curlfile
| From: | ohcc at 163 dot com | Date: | Mon, 04 Dec 2017 06:23:39 +0000 |
| Subject: | note 121971 added to class.curlfile | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209306@lists.php.net to get a copy of this message | ||
This is how to upload two or more files at once with cURLFile.
With modern browser support, you can upload many files at one time if the multiple attribute is
given.
<input type="file" name="file[]" muliple />
With outdated browser you can place many input elements to do that.
<input type="file" name="file[]" />
<input type="file" name="file[]" />
<input type="file" name="file[]" />
Here's the php code to handle multiple uploads.
<?php
$cURLHandle = curl_init();
// ... more code ...
$postFields = array(
'file[0]' => new cURLFile($file1, $mimetype1, $basename1),
'file[1]' => new cURLFile($file2, $mimetype2, $basename2)
)
curl_setopt($cURLHandle, CURLOPT_POSTFIELDS, $fields);
// ... more code ...
?>
Each file's mimetype can be determined by finfo, and its basename can be fetched from $_FILES
if it is uploaded from the client-end or by pathinfo() if it is locally stored.
Don't leave the square brackets in ''file[0]'' empty like
'file[]', in that way only the last file will be received by the remote server.
----
Server IP: 208.43.231.9
Probable Submitter: 118.117.77.148
----
Manual Page -- http://php.net/manual/en/class.curlfile.php
Edit -- https://master.php.net/note/edit/121971
Del: integrated -- https://master.php.net/note/delete/121971/integrated
Del: useless -- https://master.php.net/note/delete/121971/useless
Del: bad code -- https://master.php.net/note/delete/121971/bad+code
Del: spam -- https://master.php.net/note/delete/121971/spam
Del: non-english -- https://master.php.net/note/delete/121971/non-english
Del: in docs -- https://master.php.net/note/delete/121971/in+docs
Del: other reasons-- https://master.php.net/note/delete/121971
Reject -- https://master.php.net/note/reject/121971
Search -- https://master.php.net/manage/user-notes.php