http
function Httpdownload ($url, $path = ", $filename =", $timeout = all, $type = 0) {if ($url = = ") { return false; }//Get remote file data if ($type = = = 0) {$ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_connecttimeout, $timeout);//Maximum Execution time curl_setopt ($ch, Curlopt_timeout, $timeout);//most Long wait time $file = curl_exec ($ch); Curl_close ($ch); } if ($type = = = 1) {Ob_start (); ReadFile ($url); $file = Ob_get_contents (); Ob_end_clean (); } if ($type = = = 2) {$file = file_get_contents ($url); }//Determine if the downloaded data is empty download timeout problem if (empty ($file)) {throw new \exception ("Download error, unable to get download file! "); }//no path specifiedDefault current path if ($path = = =) {$path = "./"; }//If the name is empty if ($filename = = = "") {$filename = MD5 ($file); }//Get the suffix name $ext = substr ($url, Strrpos ($url, '. ')); if ($ext && strlen ($ext) < 5) {$filename. = $ext; }//Prevent "/" is not added $path = RTrim ($path, "/"). "/"; Var_dump ($path. $filename);d ie (); $FP 2 = @fopen ($path. $filename, ' a '); Fwrite ($fp 2, $file); Fclose ($fp 2); echo "Finish"; return $filename; }
https:
function Httpsdownload ($url, $path = ", $filename =", $timeout = all, $type = 0) {if ($url = = ") { return false; }//Get remote file data if ($type = = = 0) {$ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_connecttimeout, $timeout);//Maximum Execution time curl_setopt ($ch, Curlopt_timeout, $timeout);//Longest wait Inter-curl_setopt ($ch, Curlopt_ssl_verifypeer, false); curl_setopt ($ch, Curlopt_ssl_verifyhost, false); $file = curl_exec ($ch); Curl_close ($ch); } if ($type = = = 1) {Ob_start (); ReadFile ($url); $file = Ob_get_contents (); Ob_end_clean (); } if ($type = = = 2) {$file = file_get_contents ($url); }//Determine if the downloaded data is empty download timeout problem if (empty ($file)) {throw new \exception ("Download error, unable to get download file! "); } If no path is specified, the default current path if ($path = = = ") {$path ="./"; }//If the name is empty if ($filename = = = "") {$filename = MD5 ($file); }//Get the suffix name $ext = substr ($url, Strrpos ($url, '. ')); if ($ext && strlen ($ext) < 5) {$filename. = $ext; }//Prevent "/" is not added $path = RTrim ($path, "/"). "/"; Var_dump ($path. $filename);d ie (); $FP 2 = @fopen ($path. $filename, ' a '); Fwrite ($fp 2, $file); Fclose ($fp 2); echo "Finish"; return $filename; }
Http-https php File download