CURLFile::__construct
(PHP 5 >= 5.5.0, PHP 7)
CURLFile::__construct -- curl_file_create — Create a CURLFile object
描述
面向对象的风格
public CURLFile::__construct ( string $filename [, string $mimetype [, string $postname ]] )
程序风格
CURLFile curl_file_create ( string $filename [, string $mimetype [, string $postname ]] )
创建一个CURLFile对象,用于上传文件CURLOPT_POSTFIELDS
。
参数
filename
将要上传的文件的路径。
mimetype
文件的Mimetype。
postname
上传数据中要使用的文件的名称。
返回值
返回一个CURLFile对象。
例子
Example #1 CURLFile::__construct() example
面向对象的风格
<?php
/*?http://example.com/upload.php:
<?php?var_dump($_FILES);??>
*/
//?Create?a?cURL?handle
$ch?=?curl_init('http://example.com/upload.php');
//?Create?a?CURLFile?object
$cfile?=?new?CURLFile('cats.jpg','image/jpeg','test_name');
//?Assign?POST?data
$data?=?array('test_file'?=>?$cfile);
curl_setopt($ch,?CURLOPT_POST,1);
curl_setopt($ch,?CURLOPT_POSTFIELDS,?$data);
//?Execute?the?handle
curl_exec($ch);
?>
程序风格
<?php
/*?http://example.com/upload.php:
<?php?var_dump($_FILES);??>
*/
//?Create?a?cURL?handle
$ch?=?curl_init('http://example.com/upload.php');
//?Create?a?CURLFile?object
$cfile?=?curl_file_create('cats.jpg','image/jpeg','test_name');
//?Assign?POST?data
$data?=?array('test_file'?=>?$cfile);
curl_setopt($ch,?CURLOPT_POST,1);
curl_setopt($ch,?CURLOPT_POSTFIELDS,?$data);
//?Execute?the?handle
curl_exec($ch);
?>
上面的例子将输出:
array(1) {
["test_file"]=>
array(5) {
["name"]=>
string(9) "test_name"
["type"]=>
string(10) "image/jpeg"
["tmp_name"]=>
string(14) "/tmp/phpPC9Kbx"
["error"]=>
int(0)
["size"]=>
int(46334)
}
}
← CURLFile
CURLFile::getFilename →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com