<? header("Content-type:image/jpeg"); function read_url(http://pic4.phprm.com/2013/01/22/http://pic4.phprm.com/2013/01/22/$str.jpg.jpg) { $file=fopen($str,"r"); while(!feof($file)) { $result.=fgets($file,9999); } fclose($file); return $result; } function save_img($str) { $result=read_url($str); $result=str_replace(""","",$result); $result=str_replace("'","",$result); preg_match_all('/<imgssrc=(http://.*?)(s(.*?)>|>)/i',$result,$matches); foreach($matches[1] as $value) { echo $value."<br>n"; //GrabImage($value,$filename=""); } } // $url 是远程图片的完整URL地址,不能为空。 // $filename 是可选变量: 如果为空,本地文件名将基于时间和日期 // 自动生成. function GrabImage($url,$filename="") { if($url==""):return false;endif; $path="download/"; //指定存储文件夹 //若文件不存在,则创建; if(!file_exists($path)){ mkdir($path); } if($filename=="") { $ext=strrchr($url,"."); if($ext!=".gif" && $ext!=".jpg"):return false;endif; $filename=$path.date("dMYHis").$ext; } ob_start(); readfile($url); $img = ob_get_contents(); ob_end_clean(); $size = strlen($img); $fp2=@fopen($filename, "a"); fwrite($fp2,$img); fclose($fp2); return $filename; } save_img("http://www.phprm.com"); ?> |