从 PHP 5.5 升级到 5.6 后,我的 cURL 上传失败:
$aPost = array(
'file' => "@".$localFile,
'default_file' => 'html_version.html',
'expiration' => (2*31*24*60*60)
)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiurl);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
curl_setopt($ch, CURLOPT_POSTFIELDS, $aPost);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$sResponse = curl_exec ($ch);
该文件在目标系统上似乎是空的。
其实我在开始提问的时候就找到了答案。 PHP 5.5 中的curl 包含一个新变量:CURLOPT_SAFE_UPLOAD
这被设置为false
PHP 5.5 中默认为,并切换为默认值true
在 PHP 5.6 中。
出于安全原因,这将阻止“@”上传修饰符工作 - 用户输入可能包含恶意上传请求。您可以使用CURLFile
类上传文件CURLOPT_SAFE_UPLOAD
被设定为true
或者(如果你确定你的变量是安全的,你可以切换CURLOPT_SAFE_UPLOAD
to false
手动):
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
这是让我朝着正确方向搜索的信息来源:http://comments.gmane.org/gmane.comp.php.devel/87521 http://comments.gmane.org/gmane.comp.php.devel/87521
更改后的功能中也提到了这一点:http://php.net/manual/en/migration56.changed-functions.php http://php.net/manual/en/migration56.changed-functions.php但不是在向后不兼容的变化中,真的让我失望了......
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)