How to download the following code to the specified directory

Source: Internet
Author: User
The following code how to download to the specified directory
/**
* Crawl Remote Pictures
*
* @param string $url remote picture path
* @param string $filename Local store file name
*/
function Grabimage ($url, $filename = ") {
if ($url = = ") {
return false; Returns False if the $url is empty;
}
$ext _name = STRRCHR ($url, '. '); Get the name extension of a picture
if ($ext _name! = '. gif ' && $ext _name! = '. jpg ' && $ext _name! = '. bmp ' && $ext _name! = '. png ') {
return false; Format is not in allowed range
}
if ($filename = = ") {
$filename = Time (). $ext _name; Named by Time stamp
}
Start capturing
Ob_start ();
ReadFile ($url);
$img _data = ob_get_contents ();
Ob_end_clean ();
$size = strlen ($img _data);
$local _file = fopen ($filename, ' a ');
Fwrite ($local _file, $img _data);
Fclose ($local _file);
return $filename;
}


The above code can download remote pictures to local, but how to download to the specified directory and get the downloaded file name and directory
Trouble to know the master directly to the code, thank you

Share to: more


------Solution--------------------
This function is not OK, the second parameter you can not be arbitrarily specified? For example, the second parameter passed e:/test/1_u013032668.jpg in, and naturally downloaded to the E:/test directory.
  • 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.