Home >Backend Development >PHP Tutorial >php7 curl upload file

php7 curl upload file

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-09-15 11:15:081970browse

php7 uses curl to upload files and returns error code 26; the code is as follows:

<code>    $size    =    filesize($path);//文件大小
    $ch = curl_init($url);
    $cfile = curl_file_create($path);
    if (is_null($post_data)) {
        $data = array('media' => $cfile);
    }else{
        $data = array('media' => $cfile,'description'=>$post_data);
    }
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_INFILESIZE,$size);
    curl_setopt($ch, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
    $info    =    curl_exec($ch);
    if (curl_errno($ch)) {
        var_dump(curl_errno($ch));
        return FALSE;
    }
    curl_close($ch); // 关闭CURL会话
    return $info; // 返回数据</code>

I used the CURLFile function after checking the manual, but the error returned was still error code 26, or there was a lack of multimedia problems, etc.

<code>    $cfile  =   new \CURLFile($path,$upload_type,$upload_name);   </code>
Statement:
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