php curl上传文件$_FILES为空问题
2016-08-18 11:28
393 查看
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');
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);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
?>
解决方法2:
5.6版本下
<?php
/* http://localhost/upload.php: print_r($_POST);
print_r($_FILES);
*/
$ch = curl_init();
$data = array('name' => 'Foo', 'file' => new \CURLFile(realpath('/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);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
?>
相关文章:
php curl文件上传兼容php5.0~5.6各版本
http://www.cnblogs.com/zqifa/p/php-curl-2.html
发送的代码(完全是官方的示例)
<?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');
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);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
?>
解决方法2:
5.6版本下
<?php
/* http://localhost/upload.php: print_r($_POST);
print_r($_FILES);
*/
$ch = curl_init();
$data = array('name' => 'Foo', 'file' => new \CURLFile(realpath('/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);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
?>
相关文章:
php curl文件上传兼容php5.0~5.6各版本
http://www.cnblogs.com/zqifa/p/php-curl-2.html
相关文章推荐
- php curl上传文件$_FILES为空问题
- php curl上传文件$_FILES为空的问题
- PHP curl 上传文件版本兼容问题
- PHP学习之路之PHP文件上传需要考虑的问题以及解决方法($_FILES,$_SERVER,substr,strrpos,file_exists,move_uploaded_file,is_uploaded_file,mkdir)
- PHP curl 上传文件版本兼容问题
- 关于git上传文件过大报错的问题 remote: warning: Large files detected.
- PHP CURL POST方式上传文件中遇到的问题及解决方案
- 微信小程序文件上传php服务器$_FILES[xxx][type] = application/octet-stream问题
- 再问struts多文件上传的问题
- 蛙蛙推荐:大文件上传问题,整理自csdn论坛
- 想写写个socket解决大文件上传的问题
- [导入]上传大文件时,找不到服务器的错误问题!
- IIS6 ASP 无法支持大文件上传的问题
- 于Excel文件上传读取数据的问题
- asp.net上传大文件碰到问题 SlickUpload来解决 当前版本为2.5.2 应该是开源的
- [导入]研究大文件上传问题。
- [导入]我就不信还解决不了这个问题!!大文件上传!
- 解决在Windows 2003中无法上传超过200K文件以及无法下载超过4M的文件问题
- 研究了三天的文件上传(jspsmart实现)file和text表单同时提交的问题
- 关于文件的上传问题!