2005-11-28, 06:11 PM
|
#2
|
注册日期: 2003-10-22
帖子: 11,051
积分:6
精华:24
现金:14342金币
资产:29325299金币
|
回复: PHP保存远程图片到本地
dedecms
PHP 代码:
if(!empty($saveremoteimg)) { $body = stripslashes($body); $img_array = array(); preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\/\/(.*)\.(gif|jpg|jpeg|bmp|png))/isU",$body,$img_array); $img_array = array_unique($img_array[2]); set_time_limit(0); $imgUrl = $img_dir."/".strftime("%Y%m%d",time()); $imgPath = $base_dir.$imgUrl; $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); $fileurl = $imgUrl."/".$milliSecond.$key.".".substr($value,-3,3); if($get_file) { $fp = @fopen($rndFileName,"w"); @fwrite($fp,$get_file); @fclose($fp); } $body = ereg_replace($value,$fileurl,$body); } $body = addslashes($body); }
|
|
|
|