CURL模拟打开本地文件上传,路径中有中文就失败

liumingyu218 2020-01-16 11:38:31
CURL模拟打开本地文件上传,路径中有中文就失败。
$file= "C:\\Users\\Administrator\\Pictures\\2019-11-01_1572578500_5dbba4c44b3ec.jpg";路径中文目标地址收不到数据
第一次搞,有没有大神

$httpInfo = array();
//$file路径出中文就不行?
$file= "C:\\Users\\Administrator\\Pictures\\2019-11-01_1572578500_5dbba4c44b3ec.jpg";
$obj =new \CURLFile($file);//也可以用这种方式 一定要加前面的“\”不然会报错
$params['upfile'] = $obj;//就像<input type="file" name="buffer" />
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Accept-Language: zh-CN,zh;q=0.9','Referer: http://localhost','Content-Type: multipart/form-data'));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING ,'gzip,deflate');
if ($https) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 对认证证书来源的检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在
}
if ($ispost) {
var_dump($params);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_URL, $url);

} else {
if ($params) {
if (is_array($params)) {
$params = http_build_query($params);
}
curl_setopt($ch, CURLOPT_URL, $url . '?' . $params);
} else {
curl_setopt($ch, CURLOPT_URL, $url);
}
}

$response = curl_exec($ch);
if ($response === FALSE) {
//echo "cURL Error: " . curl_error($ch);
return false;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$httpInfo = array_merge($httpInfo, curl_getinfo($ch));
curl_close($ch);
return $response;
...全文
255 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
老虎爱代码 2020-01-16
  • 打赏
  • 举报
回复
编码问题,设置下编码格式

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧