phpcms不能保存遠(yuǎn)程圖片怎么辦?
phpcms v9默認(rèn)情況下只能保存http協(xié)議的遠(yuǎn)程圖片,當(dāng)然,你也可以自己設(shè)置是否保存。不知道在哪里設(shè)置?后臺->內(nèi)容->模型管理->文章模型-字段管理->content字段-修改,見下圖:
言歸正傳,現(xiàn)在有很多網(wǎng)站為了安全,啟用了https協(xié)議,從這些網(wǎng)站上復(fù)制過來的圖片也是https的,這種情況下phpcms是不能夠自動保存遠(yuǎn)程圖片的。修改phpcms/libs/classes/attachment.class.php文件中的fillurl函數(shù)就可以了,如下:
/** *?補(bǔ)全網(wǎng)址 * *?@paramstring$surl源地址 *?@paramstring$absurl相對地址 *?@paramstring$basehref網(wǎng)址 *?@returnstring網(wǎng)址 *?增加對遠(yuǎn)程https協(xié)議下圖片的本地化保存 */ 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)<p>其中https為新增的,原來沒有。</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p><p>PHP中文網(wǎng),大量的免費(fèi)<a href="https://www.php.cn/cms/phpcms/" target="_blank">PHPCMS教程</a>,歡迎在線學(xué)習(xí)!</p>
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載。
THE END