Home >Backend Development >PHP Tutorial >PHP save remote pictures to local

PHP save remote pictures to local

WBOY
WBOYOriginal
2016-07-25 09:07:05983browse
Simple file operations, save remote pictures locally.
  1. function get_file($url,$folder,$pic_name){
  2. set_time_limit(24*60*60); //Limit the maximum execution time
  3. $destination_folder=$folder?$folder.' /':''; //File download and save directory
  4. $newfname=$destination_folder.$pic_name;//File PATH
  5. $file=fopen($url,'rb');
  6. if($file){
  7. $ newf=fopen($newfname,'wb');
  8. if($newf){
  9. while(!feof($file)){
  10. fwrite($newf,fread($file,1024*8),1024*8) ;
  11. }
  12. }
  13. if($file){
  14. fclose($file);
  15. }
  16. if($newf){
  17. fclose($newf);
  18. }
  19. }
  20. }
  21. get_file("http://www .baidu.com/img/baidu_logo.gif","file","baidu.jpg");
  22. ?>
Copy code


Statement:
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