/ Published in: PHP
Expand |
Embed | Plain Text
<?php function download($url, $file2save, $directory = 'files') { $curl = curl_init(); if($curl) { if($fp) { if( !curl_setopt($curl, CURLOPT_URL, $url) ) return "FAIL: curl_setopt(CURLOPT_URL)"; // uncommment this line below to use http authentication // if( !curl_setopt($ch, CURLOPT_USERPWD, 'username:password') ) return "FAIL: curl_setopt(CURLOPT_USERPWD)"; if( !curl_setopt($curl, CURLOPT_FILE, $fp) ) return "FAIL: curl_setopt(CURLOPT_FILE)"; if( !curl_setopt($curl, CURLOPT_HEADER, 0) ) return "FAIL: curl_setopt(CURLOPT_HEADER)"; if( !curl_exec($curl) ) return "FAIL: curl_exec()"; curl_close($curl); return "It Worked!! : $file2save [$url]"; } else return "FAIL: fopen()"; } else return "FAIL: curl_init()"; } // Download from 'example.com' to 'example.txt'
You need to login to post a comment.
