The code for saving remote images does not know how to modify the save path.

Source: Internet
Author: User
I don't know how to modify the save path of the code for saving remote images ;? Php & nbsp; Function: & nbsp; obtain the remote image and save it locally & nbsp; are you sure you have the permission to write files to the local server?

//
// Function: obtain the remote image and save it to the local device.
//
//
// Make sure you have the permission to write files to the local server
//
//
// Variable description:
// $ Url is the complete URL of the remote image. it cannot be blank.
// $ Filename is an optional variable. if it is null, the local file name is based on the time and date.
// Automatically generated.

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

// Php programmer site


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


$ Fp2 = @ fopen ($ filename, "");
Fwrite ($ fp2, $ img );
Fclose ($ fp2 );

Return $ filename;
}


$ Img = GrabImage ("http://www.ljj.com/d/untitled.jpg ","");
// Php programmer site


If ($ img): echo'
    
';
Else: echo "false ";
Endif;
?>

The code found in the download area does not know how to modify it. then, you can save the attachment to the specified directory.

------ Solution --------------------
No need to change the code. For example you call: $ img = GrabImage ("http://www.ljj.com/d/untitled.jpg", "./test/aa.png ");

It will be stored in the testdirectory named AA.png. Of course, the directory you pass must exist.

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.