Model Management->Article Model-Field Management->Content Field"; then modify the word attribute to "Save remote images"."/> Model Management->Article Model-Field Management->Content Field"; then modify the word attribute to "Save remote images".">

Home >CMS Tutorial >PHPCMS >What should I do if phpcms cannot save remote images?

What should I do if phpcms cannot save remote images?

藏色散人
藏色散人Original
2020-02-05 10:11:082426browse

What should I do if phpcms cannot save remote images?

What should I do if phpcms cannot save remote images?

phpcms v9 can only save remote images of http protocol by default. Of course, you can also set whether to save them yourself. Not sure where to set it? Backend->Content->Model Management->Article Model-Field Management->Content Field-Modify, see the picture below:

What should I do if phpcms cannot save remote images?

Getting back to the subject, there are many now For the sake of security, the website has enabled the https protocol, and the pictures copied from these websites are also https. In this case, phpcms cannot automatically save the remote pictures. Just modify the fillurl function in the phpcms/libs/classes/attachment.class.php file, as follows:

/**
* 补全网址
*
* @paramstring$surl源地址
* @paramstring$absurl相对地址
* @paramstring$basehref网址
* @returnstring网址
* 增加对远程https协议下图片的本地化保存
*/
function fillurl($surl, $absurl, $basehref = '') {
if($basehref != '') {
$preurl = strtolower(substr($surl,0,6));
if($preurl=='http://' || $preurl=='https://' || $preurl=='ftp://' ||$preurl=='mms://' || $preurl=='rtsp://' || $preurl=='thunde' || $preurl=='emule://'|| $preurl=='ed2k://')
return  $surl;
else
return $basehref.'/'.$surl;
}
$i = 0;
$dstr = '';
$pstr = '';
$okurl = '';
$pathStep = 0;
$surl = trim($surl);
if($surl=='') return '';
$urls = @parse_url(SITE_URL);
$HomeUrl = $urls['host'];
$BaseUrlPath = $HomeUrl.$urls['path'];
$BaseUrlPath = preg_replace("/\/([^\/]*)\.(.*)$/",'/',$BaseUrlPath);
$BaseUrlPath = preg_replace("/\/$/",'',$BaseUrlPath);
$pos = strpos($surl,'#');
if($pos>0) $surl = substr($surl,0,$pos);
if($surl[0]=='/') {
$okurl = 'http://'.$HomeUrl.'/'.$surl;
} elseif($surl[0] == '.') {
if(strlen($surl)<=2) return &#39;&#39;;
elseif($surl[0]==&#39;/&#39;) {
$okurl = &#39;http://&#39;.$BaseUrlPath.&#39;/&#39;.substr($surl,2,strlen($surl)-2);
} else {
$urls = explode(&#39;/&#39;,$surl);
foreach($urls as $u) {
if($u=="..") $pathStep++;
else if($i<count($urls)-1) $dstr .= $urls[$i].&#39;/&#39;;
else $dstr .= $urls[$i];
$i++;
}
$urls = explode(&#39;/&#39;, $BaseUrlPath);
if(count($urls) <= $pathStep)
return &#39;&#39;;
else {
$pstr = &#39;http://&#39;;
for($i=0;$i<count($urls)-$pathStep;$i++) {
$pstr .= $urls[$i].&#39;/&#39;;
}
$okurl = $pstr.$dstr;
}
}
} else {
$preurl = strtolower(substr($surl,0,6));
if(strlen($surl)<7)
$okurl = &#39;http://&#39;.$BaseUrlPath.&#39;/&#39;.$surl;
elseif($preurl=="http:/" || $preurl=="https:" ||$preurl==&#39;ftp://&#39; ||$preurl==&#39;mms://&#39; || $preurl=="rtsp://" || $preurl==&#39;thunde&#39; || $preurl==&#39;emule:&#39;|| $preurl==&#39;ed2k:/&#39;)
$okurl = $surl;
else
$okurl = &#39;http://&#39;.$BaseUrlPath.&#39;/&#39;.$surl;
}
$preurl = strtolower(substr($okurl,0,6));
if($preurl==&#39;ftp://&#39; || $preurl==&#39;mms://&#39; || $preurl==&#39;rtsp://&#39; || $preurl==&#39;thunde&#39; || $preurl==&#39;emule:&#39;|| $preurl==&#39;ed2k:/&#39;) {
return $okurl;
} else {
$okurl = preg_replace(&#39;/^(http:\/\/)/i&#39;,&#39;&#39;,$okurl);
$okurl = preg_replace(&#39;/^(https:\/\/)/i&#39;,&#39;&#39;,$okurl);
$okurl = preg_replace(&#39;/\/{1,}/i&#39;,&#39;/&#39;,$okurl);
return &#39;http://&#39;.$okurl;
}
}

Among them, https is newly added and did not exist before.

PHP Chinese website, a large number of free PHPCMS tutorials, welcome to learn online!

The above is the detailed content of What should I do if phpcms cannot save remote images?. For more information, please follow other related articles on the PHP Chinese website!

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