原文网址:https://www.youyong.top/article/1158dfb6eb3e
踩到一个php curl的坑
原文网址:https://www.youyong.top/article/1158dfb6eb3e
踩到一个php curl的坑
原文网址:https://www.youyong.top/article/1158dfb6eb3e
$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);
file => @ . realpath(xxx)
方式看似没问题,也是大家常用上传方法。Actually I found the answer while starting the question. There is a new Variable included with curl in PHP 5.5: CURLOPT_SAFE_UPLOAD this is set to false by default in PHP 5.5 and is switched to a default of true in PHP 5.6.
This will prevent the '@' upload modifier from working for security reasons - user input could contain malicious upload requests. You can use the CURLFile class to upload files while CURLOPT_SAFE_UPLOAD is set to true or (if you're sure your variables are safe you can switch the CURLOPT_SAFE_UPLOAD to false manually):
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
PHP 5.5另外引入了CURL_SAFE_UPLOAD选项,可以强制PHP的cURL模块拒绝旧的@语法,仅接受CURLFile式的文件。5.5的默认值为false,5.6的默认值为true。Are you fuck kidding me?!
解决方法
if (class_exists('\CURLFile')) {
$field = array('fieldname' => new \CURLFile(realpath($filepath)));
} else {
$field = array('fieldname' => '@' . realpath($filepath));
}
代码应该回归本源。我们的实际需求其实是:有CURLFile就优先采用,没有再退化到传统@语法
if (version_compare(phpversion(), '5.4.0') >= 0)
版本号莫名其妙的出现在代码之中,不查半天PHP手册和更新历史,很难明白作者被卡在了哪个功能的变更上。
查找官方根源
作者声明:本篇文章系本人原创,欢迎分享,但未经许可,谢绝转载。
共 0 条留言
Linux php-fpm报错:allow_call_time_pass_reference
6款程序员必备的开源中文汉字拼音转换及处理工具 (PHP Java .net)
PHP Fatal error: Allowed memory size of bytes exhausted
改了php.ini中的open_basedir仍报错open_basedir restriction in effect
php call_user_fun Call-time pass-by-reference has been remov
iPhone X 跌破发行价,苏宁200亿入股恒大 | 财经日日评
资深黄牛现身说法:iPhone X价格秒变不停,就像炒股一样
手机扫一扫
分享文章