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)!