PHP CURL上传文件出现413 Request Entity Too Large

php在使用CURL上传文件时出现413 Request Entity Too Large,网上也查找了很多方案,但是都不起作用

经仔细检查,发现curl_setopt的各个参数设置的顺序也会有影响。

<pre name="code" class="html"><pre name="code" class="html">$downloadPath = 'E:\wamp\www\11.mp3';
$uploadUrl = "http://localhost:8000/wx_index/55.php";
if (PHP_VERSION >= '5.5.0') {
	$uploadData = array('file' => new CURLFile($downloadPath));
}
else {
	$uploadData = array('file' => '@E:\wamp\www\11.mp3');
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $uploadUrl);
curl_setopt($curl, CURLOPT_POSTFIELDS, $uploadData);
curl_setopt($curl, CURLOPT_POST, true);
$voice = curl_exec($curl);
curl_close($curl);
 
 上面代码执行会出现413错误。 

CURLOPT_POST和CURLOPT_POSTFIELDS位置对调,就能发送成功。代码如下;

$downloadPath = 'E:\wamp\www\11.mp3';
$uploadUrl = "http://localhost:8000/wx_index/55.php";
if (PHP_VERSION >= '5.5.0') {
	$uploadData = array('file' => new CURLFile($downloadPath));
}
else {
	$uploadData = array('file' => '@E:\wamp\www\11.mp3');
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $uploadUrl);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $uploadData);
$voice = curl_exec($curl);
curl_close($curl);


下面是55.php

print_r($_FILES);
copy($_FILES['file']['tmp_name'], $_FILES['file']['name']);


 这只是本人遇到的问题,可能还有其他造成该错误的原因,具体要自己多实践了。对于其他的参数设置顺序是否会导致其他错误,还未经实践。如果发现,请给我留个言,以免以后走弯路。 

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $uploadData);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值