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=$f ile> $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-dispositio n: attachment; filename=$file");
$file = $_REQUEST['file'];
echo $file;
if (substr($file,0,5) != '/tmp/') {
readfile($file);
} else {
echo "Error reading file";
}
?>
Thanks!
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=$f
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-dispositio
$file = $_REQUEST['file'];
echo $file;
if (substr($file,0,5) != '/tmp/') {
readfile($file);
} else {
echo "Error reading file";
}
?>
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.