Hello guys, I want to create download file script, I used an id to refer to a file in my site
here is the script
get the id and search in database for filename then return it for download.
<?php
if ($_GET['file']) {
$id = (int)$_GET['file'];
$sql= "SELECT filename FROM uploads WHERE id = $id LIMIT 1";
$run = mysql_query($sql);
$data = mysql_fetch_assoc($run);
// Define the path to file
$file = 'uploads/'.$data['filename'];
if(!file_exists($file))
{
// File doesn't exist, output error
die('<div class="row-fluid"><span class="label label-important"><h1>File Not Found</h1></span></div>');
}
else
{
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=".$file);
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
// Read the file from disk
readfile($file);
exit();
}
}else {
echo ('<div class="row-fluid"><span class="label label-important"><h1>No File Chosen</h1></span></div>');
}
?>
and here is the results
what should I do ?