Link to home
Start Free TrialLog in
Avatar of nova2002
nova2002

asked on

Download a file

I would like to create a download link to a file outside the web server area, for example in the /tmp/

I could create a list of the files, but I dont know how to make it downloadable.

So far, I can create this link :

<a href="get_file.php?file=$file> $file </a>

Anyone know how to code the "get_file.php" so it will download the $file?

The $file is not in the web server area, for example /tmp/test.txt

I tried it like this (see below), but it does not work:

<?php

  header("Content-type: application/octet-stream");
  header("Content-disposition: attachment; filename=$file");

  $file = $_REQUEST['file'];
 
  echo $file;
 
  if (substr($file,0,5) != '/tmp/') {
     readfile($file);
  } else {
     echo "Error reading file";
  }

?>


Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial