如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
php获取远程图片并保存到本地hp获取远程图片并保存到本地,这是一个比较通用的功能。以下函数也写的比较通用,只需要传入一段html代码。php获取远程图片并保存到本地,这个函数一般应用在编辑器和采集器中。123456789101112131415161718192021222324functionauto_save_image($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]);set_time_limit(0);$imgPath="uploadFiles/".date("Ym")."/";$milliSecond=strftime("%H%M%S",time());if(!is_dir($imgPath))@mkdir($imgPath,0777);foreach($img_arrayas$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;}php读远程图片和PHP保存远程图片到本地php读远程图片<?phpheader('Content-Type:image/jpg');echofile_get_contents("");?>PHP保存远程图片到本地方法一:print_rstream_get_wrappers();查看是否wrapperhttp,若包含http,则:copy("");即可。方法二:$img=file_get_contents("HYPERLINK"http://www.baidu.com/img/baidu_logo.gif"http://www.baidu.com/img/baidu_logo.gif");$ret=@file_put_contents('abc.jpg',$img);亦可。============================================另附:<?php////Function:获取远程图片并把它保存到本地//////确定您有把文件写入本地服务器的权限////变量说明://$url是远程图片的完整URL地址,不能为空。//$filename是可选变量:如果为空,本地文件名将基于时间和日期//自动生成.functionGrabImage($url,$filename=""){if($url==""):returnfalse;endif;if($filename==""){$ext=strrchr($url,".");if($ext!=".gif"&&$ext!=".jpg"):returnfalse;endif;$filename=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;}$img=GrabImage("http://www.phpzy.com/login.gif","");if($img):echo'<pre><imgsrc="'.$img.'"></pre>';else:echo"false";endif;?>dedecms中的:if(!emptyempty($saveremoteimg)){$body=stripslashes($body);$img_array=array();preg_match_all("/(src|SRC)=[\"|'|]{0,}(http:\/\/(.*)\.(gif|jpg|jpeg|bmp|png))/isU",$body,