phpcms v9添加文章中的部分图片无法自动本地化解决

远程图片无法本地化一般都是由于网站加了SSL造成的,官方网站默认获取图片使用的是copy()函数,所以部分图片无法自动本地化,所以修改成curl的方式获取图片,
修改之前请确保网站开启了curl函数。

(1)具体修改如下: phpcms/libs/classes/attachment.class.php 添加了一个函数
  1. /* 
  2.     **  采集https内容 
  3.      */ 
  4.     protected static function curl_getpic($file,$newfile) {    
  5.         if (!function_exists('curl_init')) {    
  6.             throw new Exception('server not install curl');    
  7.         }    
  8.         $ch = curl_init();  
  9.         curl_setopt($ch, CURLOPT_URL,$file);  
  10.         curl_setopt($ch, CURLOPT_HEADER,0);  
  11.         curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//禁止调用时就输出获取到的数据  
  12.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);  
  13.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);  
  14.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);  
  15.         $data = curl_exec($ch);  
  16.         curl_close($ch);  
  17.         $write = @fopen($newfile,"w");  
  18.         fwrite($write,$data);  
  19.         fclose($write);  
  20.         return TRUE;  
  21.     }    
(2)找到大概171行代码:
  1. if($upload_func($file, $newfile)) { 
改成:
  1. if($this->curl_getpic($file, $newfile)) { 
保存测试一下试试!

此处修改和采集无法采集https网站内容采用方法一样!


联系我们

在线咨询:点击这里给我发消息

邮件:w420220301@qq.com