PHPCURL allows you to remotely download an object to a local device. PHPCURL allows you to remotely download a file to a local PHPCURL to remotely download the file to a local location. the result returned by this function includes the download duration, saved file name, php curl is used to remotely download files to the local device.
Php curl allows you to remotely download an object to a local device. the result returned by this function includes the download duration, saved file name, and download method. The writing is rough. if you have good suggestions and improvement plans, please leave a message to me!
The code is as follows:
'; Print_r ($ result); function httpcopy ($ url, $ file = '', $ timeout = 60) {$ file = empty ($ file )? Pathinfo ($ url, PATHINFO_BASENAME): $ file; $ dir = pathinfo ($ file, PATHINFO_DIRNAME );! Is_dir ($ dir) & @ mkdir ($ dir, 0755, true); $ url = str_replace (''," % 20 ", $ url ); $ result = array ('filename' => '', 'way' =>'', 'size' => 0, 'endtime' => 0 ); $ startTime = explode ('', microtime (); $ startTime = (float) $ startTime [0] + (float) $ startTime [1]; if (function_exists ('curl _ init ') {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_TIMEOUT, $ timeout); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, TRUE ); $ Temp = curl_exec ($ ch); if (@ file_put_contents ($ file, $ temp )&&! Curl_error ($ ch) {$ result ['filename'] = $ file; $ result ['way'] = 'curl '; $ result ['size'] = sprintf ('%. 3f', strlen ($ temp)/1024) ;}} else {$ opts = array ('http' => array ('method' => 'GET ', 'header' => '', 'timeout' => $ timeout); $ context = stream_context_create ($ opts); if (@ copy ($ url, $ file, $ context) {$ result ['filename'] = $ file; $ result ['way'] = 'copy '; $ result ['size'] = sprintf ('%. 3f', strlen ($ context)/1024) ;}$ endTime = explode ('', microtime (); $ endTime = (float) $ endTime [0] + (float) $ endTime [1]; $ result ['endtime'] = round ($ endTime-$ startTime) * 1000; // unit: millisecond return $ result ;}
Articles you may be interested in
- Php retrieves remote images and downloads and saves them to a local device.
- PHP uses Curl Functions to Capture webpages and download files with multiple threads
- Php methods to determine whether a remote file exists
- Php obtains the remote file size.
- Php reads the directory and lists the functions that display the files in the directory.
- Php clears (deletes) the files in the specified directory, and does not delete the directory folder.
- Php obtains all the files in the directory and saves the results to the array program.
- Use SecureCRT to upload and download files (using sz and rz commands)
Http://www.bkjia.com/PHPjc/992743.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/992743.htmlTechArticlePHP CURL realize remote download file to local php curl realize remote download file to local, the function returns the result including download time consumed, save the file name, and use the download side...