标签:curl
Example #2 上传文件
<?php
/* http://localhost/upload.php:
print_r($_POST);
print_r($_FILES);
*/
$ch =curl_init();
$data = array('name'=>'Foo','file'=>'@/home/user/test.png');
curl_setopt($ch,CURLOPT_URL,'http://localhost/upload.php');
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_exec($ch);
?>
以上例程会输出:
Array
(
[name] => Foo
)
Array
(
[file] => Array
(
[name] => test.png
[type] => image/png
[tmp_name] => /tmp/phpcpjNeQ
[error] => 0
[size] => 279
)
)
cURL 上传文件在文件名前加个@符号,然后用$_FILES接收文件。
标签:curl
原文地址:http://blog.csdn.net/xiaoxiong_web/article/details/42119481