Save the file to a local network PHP

/**
     * 通用CURL请求
     * @param $url  需要请求的url
     */
    public function upload_get_img($url)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $info = curl_exec($curl);
        curl_close($curl);

        $newFileName = SYS_UPLOAD_PATH.'/'.date('Ym', SYS_TIME).'/'.time().'.png';//保存的本地地址及文件名
        $fp2 = @fopen($newFileName, "a");
        fwrite($fp2, $info);
        fclose($fp2);
        return $newFileName;//返回新的文件路径及文件名
    }

测试url(http://xiaomabbs.oss-cn-hangzhou.aliyuncs.com/data/attachment/forum/201904/29/105012v3z04a4rz944vi30.jpg)

I do this mainly used to upload pictures, if the file did not test. If necessary take to change to change test to see if it works.

Guess you like

Origin blog.csdn.net/weixin_39616995/article/details/90902923