PHP curl enables remote download of files to local
PHP curl enables remote download of files to local, the function returns results including the time of download, the name of the saved file, and the way to download it. Write more rough, if you have good suggestions and improve the program, welcome to leave a message to me Oh!
The specific code is as follows:
';p Rint_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 ' = ' = ', ' The ' ' "' = ' = ', ' size ' =>0, ' spendtime ' =>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 [' On ' the ']= ' 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 [']= ' copy '; $result [' Size ']=sprintf ('%.3f ', strlen ($context)/1024); }} $endTime =explode (' ', Microtime ()), $endTime = (float) $endTime [0]+ (float) $endTime [1]; $result [' Spendtime ']=round ($ endtime-$startTime) *1000;//unit: milliseconds return $result;}
Articles you may be interested in
- PHP get remote picture and download save to local
- PHP uses Curl Functions to crawl Web pages and download files in multiple threads
- PHP to determine if a remote file exists
- PHP Gets the size of the remote file
- PHP reads directories and tables displays the functions of files in the directory
- PHP Empty (delete) the file under the specified directory, do not delete the Directory folder method
- PHP gets all the files in the directory and saves the results to an array of programs
- Upload and download files using SECURECRT (with SZ and RZ commands)
http://www.bkjia.com/PHPjc/992743.html www.bkjia.com true http://www.bkjia.com/PHPjc/992743.html techarticle PHP Curl Implementation of remote download files to local PHP curl implementation of remote download files to local, the function returns the results include the time of the download, the saved file name, and the use of the download party ...