Php remote image capturing (2)

Source: Internet
Author: User
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 ");
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.