php后台添加文章时,直接下载远程图片
发布时间:2023-04-27 10:42:42 所属栏目:PHP教程 来源:
导读:<?PHP
auto_save_image($str);
function auto_save_image($body){
$img_array = explode('&',$body);
/*$img_array = array();
preg_match_all("/(src)=["|&#
auto_save_image($str);
function auto_save_image($body){
$img_array = explode('&',$body);
/*$img_array = array();
preg_match_all("/(src)=["|&#
<?PHP auto_save_image($str); function auto_save_image($body){ $img_array = explode('&',$body); /*$img_array = array(); preg_match_all("/(src)=["|'| ]{0,}(http://(.*).(gif|jpg|jpeg|bmp|png))["|'| ]{0,}/isU",$body,$img_array); $img_array = array_unique($img_array[2]);*/ //用于对img标签自动匹配 set_time_limit(0); $imgPath = "uploads/allimg/".date("Ymd")."/"; $milliSecond = strftime("%H%M%s",time()); if(!is_dir($imgPath)) @mkdir($imgPath,0777); foreach($img_array as $key =>$value) $value = trim($value); $get_file = @file_get_contents($value); $rndFileName = $imgPath."/".$milliSecond.$key.".".substr($value,-3,3); if($get_file) $fp = @fopen($rndFileName,"w"); @fwrite($fp,$get_file); @fclose($fp); $body = @ereg_replace($value,$rndFileName,$body); return $body; (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐