phpcms v9添加文章中的部分图片无法自动本地化解决
远程图片无法本地化一般都是由于网站加了SSL造成的,官方网站默认获取图片使用的是copy()函数,所以部分图片无法自动本地化,所以修改成curl的方式获取图片,
修改之前请确保网站开启了curl函数。
(1)具体修改如下: phpcms/libs/classes/attachment.class.php 添加了一个函数
此处修改和采集无法采集https网站内容采用方法一样!
修改之前请确保网站开启了curl函数。
(1)具体修改如下: phpcms/libs/classes/attachment.class.php 添加了一个函数
(2)找到大概171行代码:
- /*
- ** 采集https内容
- */
- protected static function curl_getpic($file,$newfile) {
- if (!function_exists('curl_init')) {
- throw new Exception('server not install curl');
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL,$file);
- curl_setopt($ch, CURLOPT_HEADER,0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//禁止调用时就输出获取到的数据
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
- $data = curl_exec($ch);
- curl_close($ch);
- $write = @fopen($newfile,"w");
- fwrite($write,$data);
- fclose($write);
- return TRUE;
- }
改成:
- if($upload_func($file, $newfile)) {
保存测试一下试试!
- if($this->curl_getpic($file, $newfile)) {
此处修改和采集无法采集https网站内容采用方法一样!