php使用curl上传文件,代码如下:
发送的代码(完全是官方的示例)
<?php
/* http://localhost/upload.php:
print_r($_POST);
print_r($_FILES);
*/
$ch = curl_init();
$data = array('name' => 'Foo', 'file' => '@/home/vagrant/test.png');
curl_setopt($ch, CURLOPT_URL, 'http://localhost/test/curl/load_file.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
?>
接收代码(也是官方的)
<?php
print_r($_POST);
print_r($_FILES);
运行结果
php -f demo.php
Array
(
[name] => Foo
[file] => @/home/vagrant/test.png
)
Array
(
)
解决方法1:
<?php
/* http://localhost/upload.php:
print_r($_POST);
print_r($_FILES);
*/
$ch = curl_init();
$data = array('name' => 'Foo', 'file' => '@/home/vagrant/test.png');

本文介绍了使用PHP的cURL库上传文件的方法,并提供了两种不同版本的解决方案,一种适用于所有版本,另一种针对5.6版本。
最低0.47元/天 解锁文章
204

被折叠的 条评论
为什么被折叠?



