A brief discussion on the function _php instance of PHP fopen downloading remote files

Source: Internet
Author: User
Tags create directory

The

looks like this:

Download attachment function Get_file ($url, $folder = "./") {Set_time_limit (24 * 60 * 60);/Set timeout time $destination _folder = $ Folder. '/'; File download save directory, defaults to the current file directory if (!is_dir ($destination _folder)) {//To determine whether the directory exists mkdirs ($destination _folder); Record} $newfname = $destination _folder. BaseName ($url); Gets the name of the file $file = fopen ($url, "RB");   
      Remote download file, binary mode if ($file) {//If the download succeeds $NEWF = fopen ($newfname, "WB");//Far Away file if ($NEWF)///If the file is saved successfully  
    while (!feof ($file)) {//judge whether the attachment write is complete fwrite ($NEWF, Fread ($file, 1024 * 8), 1024 * 8);//I'll continue without writing. } if ($file) {fclose ($file);//close Remote file} if ($NEWF) {fclose ($NEWF);//close Local file} re  
Turn true;  The function mkdirs ($path, $mode = "0755") {if (!is_dir ($path)) {//To determine whether the directory exists mkdirs (dirname ($path), $mode); Cycle to build directory mkdir ($path, $mode);  

Create Directory} return true;  

 ///Use sample echo get_file (' xxxxx.pdf ');

The above this article on the PHP fopen download remote file function is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.

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.