PHP Implementation asynchronously writes the contents of a remote link (picture or content) to a local method

Source: Internet
Author: User
The example in this article describes a method that PHP implements to asynchronously write content (pictures or content) on a remote link locally. Share to everyone for your reference, as follows:

/** * Asynchronously writes the contents of the remote link (picture or content) to local * * @param unknown $URL * Remote address * @param unknown $SA Vename * file name saved on the server * @param unknown $path * Save path * @return Boolean */function put_file_from_url_content ($url,  $saveName = ' Tmp.png ', $path = './uploads/tmp/') {//Set run time is unlimited set_time_limit (0);  $url = Trim ($url);  $curl = Curl_init ();  Set the URL you need to crawl curl_setopt ($curl, Curlopt_url, $url);  Set HEADER curl_setopt ($curl, Curlopt_header, 0);  Sets the curl parameter, which requires the result to be saved to a string or output to the screen.  curl_setopt ($curl, Curlopt_returntransfer, 1);  Run Curl, request page $file = curl_exec ($curl);  Close URL request curl_close ($curl); Writes a file to the obtained data $filename = $path.  $saveName;  $write = @fopen ($filename, "w");  if ($write = = False) {return false;  } if (Fwrite ($write, $file) = = False) {return false;  } if (fclose ($write) = = False) {return false; } return $filename;} 


The above is the PHP implementation of the remote link content (image or content) to write the content of the local method, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.