脚本宝典收集整理的这篇文章主要介绍了有没有办法检查远程图像是否存在? PHP,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
/** * Use HTTP GET to ping an url * * /!\ Warning,the return value is always true,you must use === to test the response tyPE too. * * @param string $url * @return boolean true or the error message */ public static function pingDistantFile($url) { $options = array( CURLOPT_FOLLOWLOCATION => true,CURLOPT_URL => $url,CURLOPT_FaiLONERROR => true,// HTTP code > 400 will throw curl error ); $ch = curl_init(); curl_setopt_array($ch,$options); $return = curl_exec($ch); if ($return === false) { return curl_error($ch); } else { return true; } }
你也可以使用HEAD方法,但也许你的CDN被禁用了.
以上是脚本宝典为你收集整理的有没有办法检查远程图像是否存在? PHP全部内容,希望文章能够帮你解决有没有办法检查远程图像是否存在? PHP所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。