保存远程图片的代码不知道要如何修改保存路径坐等高手指教

WBOY
Release: 2016-06-13 10:37:32
Original
1021 people have browsed it

保存远程图片的代码不知道要怎么修改保存路径坐等高手指教

//  
//   Function:   获取远程图片并把它保存到本地
//  
//  
//   确定您有把文件写入本地服务器的权限  
//  
//  
//   变量说明:  
//   $url   是远程图片的完整URL地址,不能为空。
//   $filename   是可选变量:   如果为空,本地文件名将基于时间和日期  
//   自动生成.  

function   GrabImage($url,$filename= " ")   {    

//php程序员站


if($url== " "):return   false;endif;  

if($filename== " ")   {  
$ext=strrchr($url, ". ");  
if($ext!= ".gif "   &&   $ext!= ".jpg "):return   false;endif;   //   phperz.com  
$filename=date( "dMYHis ").$ext;  
}  

ob_start();  
readfile($url);  
$img   =   ob_get_contents();  
ob_end_clean();  
$size   =   strlen($img);    
//www.phperz.com


[email protected]($filename,   "a ");  
fwrite($fp2,$img);  
fclose($fp2);  

return   $filename;  
}  


$img=GrabImage( "http://www.ljj.com/d/untitled.jpg ", " ");    
//php程序员站


if($img):echo   '

  <img  src="'.%24img.%20'%20" alt="保存远程图片的代码不知道要如何修改保存路径坐等高手指教" >  
Copy after login
';
else:echo   "false ";
endif;  
?>  

下载区找到的代码不知道要怎么修改后可以保存附件到指定的目录中,请高手指教

------解决方案--------------------
不用改代码啊。比如你这样调用 : $img=GrabImage("http://www.ljj.com/d/untitled.jpg","./test/aa.png");

就会保存到test目录,以aa.png 命名。当然你传递的目录要存在。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!