Hi, try this: $source ="https://myapps.gia.edu/ReportCheckPortal/downloadReport.do?reportNo=1152872617&weight=1.35"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $source); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_SSLVERSION,3); $data = curl_exec ($ch); $error = curl_error($ch); curl_close ($ch); $destination ="./files/test.pdf"; $file = fopen($destination,"w+"); fputs($file, $data); fclose($file);
Hi Argento, Thank for you idea, How i can get type of file? Because i don't know type of file in dowload link. It can be zip, zar....
Hi ! You can do it in this way: $filename="this.is.the.file.png"; $filename_arr = explode(".", $filename); $count_of_elements = count($filename_arr); $file_extension = $filename_arr[$count_of_elements -1];
A couple of things. With CURLOPT_RETURNTRANSFER alone, you're loading the entire file into the memory, which may lead to problems. It's usually better if you tell cURL to write directly to a fopen() resource using CURLOPT_FILE. http://php.net/manual/en/function.curl-setopt.php#99082 And, you may not be able to get the file extension from the URL (like in the URL above). But you can usually get it from the HTTP headers. Don't rely on it, though.