Use of ob function for php remote image capturing
Use of ob function for php remote image capturing
Function GetImage ($ url, $ filename = ""){
If ($ url = ""){
Return false;
}
If ($ filename = ""){
$ Ext = strrchr ($ url ,".");
If ($ ext! = ". Gif" & $ ext! = ". Jpg "){
Return false;
}
$ Filename = time (). $ ext;
}
// File storage path
Ob_start ();
Readfile ($ url );
$ Img = ob_get_contents ();
Ob_end_clean ();
$ Size = strlen ($ img );
// File size
$ Fp2 = @ fopen ($ filename, "");
Fwrite ($ fp2, $ img );
Fclose ($ fp2 );
Return $ filename;
}
GetImage ("http://www.php100.com/statics/images/ad/ad-pw-480x60.gif ");
?>
// Open the file in the third binary format and write it to the local device.
Function get_file ($ url, $ folder, $ pic_name ){
Set_time_limit (24*60*60); // you can specify 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 );
}
}
}
// Create a file folder in the file path for this code
Get_file ("http://www.baidu.com/img/baidu_logo.gif", "file", "baidu.jpg ");
?>