Home > Backend Development > PHP Tutorial > 关于php 5.5以上 CURL上传的问题(微信"errcode":41005,"errmsg",)

关于php 5.5以上 CURL上传的问题(微信"errcode":41005,"errmsg",)

WBOY
Release: 2016-06-23 13:25:50
Original
825 people have browsed it

微信给出的方法是@+文件的路径来赋予数组来上传

$data = array(     'file' => '@/PATH/TO/FILE',     //....其他字段 ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
Copy after login

问题来了,这个@只能在5.5以下的版本用,而在5.5和5.5以上的版本这个就失效了,必须用CURLFile这个类上传:

$data = array(     'file' => new CURLFile('/PATH/TO/FILE'),     //....其他字段 ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
Copy after login

但是发现有少量的服务器不支持直接new CURLFile这个类,所以出现这种情况的时候我们可以curl_file_create来创建一个CURLFile的对象(此函数是该函数的别名: CURLFile::__construct()

$data = array(     'file' => curl_file_create('/PATH/TO/FILE'),     //....其他字段 ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
Copy after login

这样就可以了。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template