Create a CURLFile object
Syntax
curl_file_create ( string $filename [, string $mimetype = "" [, string $postname = "" ]] ) : CURLFile
Parameters
filename
Path to the file which will be uploaded.
mimetype
Mimetype of the file.
postname
Name of the file to be used in the upload data.
Return
Returns a CURLFile object.
Examples
1
<? $ch = curl_init(); $filename = 'dogs.svg'; $mimetype = 'image/svg+xml'; $postname = 'test_name'; $return = curl_file_create($filename, $mimetype, $postname); curl_setopt($ch, CURLOPT_URL, "https://osbo.com/upload/"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, array('test_file' => $return)); curl_exec($ch); curl_close($ch); ?>
2
<? $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://osbo.com/upload/"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'blob[0]' => curl_file_create(realpath('first-file.svg'), 'image/svg+xml'), 'blob[1]' => curl_file_create(realpath('second-file.txt'), 'text/plain'), 'blob[2]' => curl_file_create(realpath('third-file.exe'), 'application/octet-stream'), ] ); curl_exec($ch); curl_close($ch); ?>