function get_remote($body,$title){
$img_array = array();
$img_path = realpath("../../../upfile/news/").'/'.date("y/m/d/"); //采集远程图片保存地址
//die($img_path);
$img_rpath='/upfile/news/'.date("y/m/d/"); //设置访问地址
$body = stripslashes(strtolower($body));
preg_match_all("/(src|src)=["|'| ]{0,}(http://(.*).(gif|jpg|jpeg|png))/isu",$body,$img_array);
$img_array = array_unique($img_array[2]);
foreach ($img_array as $key => $value) {
$get_file = my_file_get_contents($value,60);
$filetime = time();
$filename = date("ymdhis",$filetime).rand(1,999).'.'.substr($value,-3,3);
if(empty($get_file)){
@sleep(10);
$get_file = my_file_get_contents($value,30);
if(empty($get_file)){
$body = preg_replace("/".addcslashes($value,"/")."/isu", '/notfound.jpg', $body);
continue;
}
}
if(!empty($get_file) ){
if( mkdirs($img_path) )
{
$fp = fopen($img_path.$filename,"w");
if(fwrite($fp,$get_file)){
$body = preg_replace("/".addcslashes($value,"/")."/isu", $img_rpath.$filename, $body);
}
fclose($fp);
@sleep(6);
}
}
}
$body =str_replace("
return $body;
}
function mkdirs($dir)
{
if(!is_dir($dir)){
if(!mkdirs(dirname($dir))){
return false;}
if(!mkdir($dir,0777)){
return false;}
}
return true;
}
|