PHP implements a method of asynchronously writing content (pictures or content) on a remote link to a local _php tips

Source: Internet
Author: User

The example in this article describes how the PHP implementation asynchronously writes the content (picture or content) on a remote link to the local method. Share to everyone for your reference, specific as follows:

/** * Writes the content (picture or content) on the remote link asynchronously to the local * @param unknown $URL * Remote address * @param unknown $s Avename * 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 to unrestricted 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 to require that the results be saved to the string or to the screen.
  curl_setopt ($curl, Curlopt_returntransfer, 1);
  Run Curl, request Web page $file = curl_exec ($curl);
  Closes the 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; }

More about PHP Interested readers can view the site topics: "Php Curl Usage Summary", "PHP Array" operation Skills Encyclopedia, "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Mathematical Calculation Skills Summary", " PHP Regular Expression Usage summary, "Summary of PHP operations and operator usage", "PHP string (String) Usage summary" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design.

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.