Home > Backend Development > PHP Tutorial > curl 上传文件 接收的地方$_FILES为空

curl 上传文件 接收的地方$_FILES为空

WBOY
Release: 2016-06-06 20:30:06
Original
1162 people have browsed it

发送的代码(完全是官方的示例)

<code><?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);
?>
</code>
Copy after login
Copy after login

接收代码(也是官方的)

<code><?php print_r($_POST);
print_r($_FILES);
</code></code>
Copy after login
Copy after login

运行结果

<code>php -f demo.php 
Array
(
    [name] => Foo
    [file] => @/home/vagrant/test.png
)
Array
(
)
</code>
Copy after login
Copy after login

本来准备贴php.ini配置的,但是没找到上传地方。请各位先看看,需要哪些配置我尽快贴出来。
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);我也加过,内容打印出来视乎帮助不大。

回复内容:

发送的代码(完全是官方的示例)

<code><?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);
?>
</code>
Copy after login
Copy after login

接收代码(也是官方的)

<code><?php print_r($_POST);
print_r($_FILES);
</code></code>
Copy after login
Copy after login

运行结果

<code>php -f demo.php 
Array
(
    [name] => Foo
    [file] => @/home/vagrant/test.png
)
Array
(
)
</code>
Copy after login
Copy after login

本来准备贴php.ini配置的,但是没找到上传地方。请各位先看看,需要哪些配置我尽快贴出来。
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);我也加过,内容打印出来视乎帮助不大。

<code>$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_SAFE_UPLOAD, false);    // 5.6 给改成 true了, 弄回去 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);
?>
</code>
Copy after login

在sf搜到的: 考虑 PHP 5.0~5.6 各版本兼容性的 cURL 文件上传

看了感觉很不错

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template