Talking about the function of php fopen to download remote files,

Source: Internet
Author: User

Talking about the function of php fopen to download remote files,

As follows:

// Download the attachment function get_file ($ url, $ folder = ". /") {set_time_limit (24*60*60); // set the timeout value $ destination_folder = $ folder. '/'; // File Download and save directory. The default value is the current file directory if (! Is_dir ($ destination_folder) {// determine whether the directory contains mkdirs ($ destination_folder); // if not, create a directory} $ newfname = $ destination_folder. basename ($ url); // get the file name $ file = fopen ($ url, "rb"); // Remote file Download, binary mode if ($ file) {// if the download is successful $ newf = fopen ($ newfname, "wb"); // if ($ newf) in the distant 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 ); // continue without writing.} if ($ file) {fclose ($ file); // close Remote file} if ($ newf) {fclose ($ newf ); // close local file} return true;} function mkdirs ($ path, $ mode = "0755") {if (! Is_dir ($ path) {// determine whether the directory contains mkdirs (dirname ($ path), $ mode); // create the directory mkdir cyclically ($ path, $ mode ); // create a directory} return true;} // use the example echo get_file('xxxxx ');

The above discussion about php fopen's function for downloading remote files is all the content that I have shared with you. I hope to give you a reference and support for the help house.

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.