curl_file_create (带路径的文件名 [, 文件mimetype , 上传数据里的文件名] ) ;
new cURLFile (带路径的文件名 [, 文件mimetype , 上传数据里的文件名] ) ;
$ch = curl_init('http://example.com/upload.php'); // 创建CURLFile对象 $cfile = curl_file_create('cats.jpg','image/jpeg','test_name'); // 分配提交的数据 $data = array('test_file' => $cfile); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_exec($ch);
upload.php打印输出:
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) } }