Simple file operations, save remote pictures locally.
- function get_file($url,$folder,$pic_name){
- set_time_limit(24*60*60); //Limit the maximum execution time
- $destination_folder=$folder?$folder.' /':''; //File download and save directory
- $newfname=$destination_folder.$pic_name;//File PATH
- $file=fopen($url,'rb');
-
- if($file){
- $ newf=fopen($newfname,'wb');
- if($newf){
- while(!feof($file)){
- fwrite($newf,fread($file,1024*8),1024*8) ;
- }
- }
- if($file){
- fclose($file);
- }
- if($newf){
- fclose($newf);
- }
- }
- }
- get_file("http://www .baidu.com/img/baidu_logo.gif","file","baidu.jpg");
- ?>
Copy code
|