php file download from url

70

$c = curl_init('https://yourURLhere.com');
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
//curl_setopt(... other options you want...)

$html = curl_exec($c);

if (curl_error($c))
    die(curl_error($c));

// Get the status code
$status = curl_getinfo($c, CURLINFO_HTTP_CODE);

curl_close($c);
1.  <?php
2.  $dir="download/";
3.  $filename=$_GET['file'];
4.  $file_path=$dir.$filename;
5.  $ctype="application/octet-stream";
6.  //
7.  if(!empty($file_path) && file_exists($file_path)){ //check keberadaan file
8.    header("Pragma:public");
9.    header("Expired:0");
10.   header("Cache-Control:must-revalidate");
11.   header("Content-Control:public");
12.   header("Content-Description: File Transfer");
13.   header("Content-Type: $ctype");
14.   header("Content-Disposition:attachment; filename=\"".basename($file_path)."\"");
15.   header("Content-Transfer-Encoding:binary");
16.   header("Content-Length:".filesize($file_path));
17.   flush();
18.   readfile($file_path);
19.   exit();
20. }else{
21.   echo "The File does not exist.";
22. }
23. ?>

Comments

Submit
0 Comments