Hello,
Recently I have been coding a system for an upload/sharing file site of mine. However I have come across an issue that I have tried to resolve, but can't.
This is the downloadnow.php (The tab closes instantly, but the download correctly starts.)
<?PHP
include_once('global.php');
$id = mysql_real_escape_string($_GET['id']);
$query = mysql_query("SELECT * FROM uploads WHERE uniq_id = '" . $id . "'");
$mainrow = mysql_fetch_array($query);
$dir = "uploads";
$file = $dir . "/" . $mainrow['file_name'];
$filename = $dir . "/" . $mainrow['file_name'];
if(file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
ob_clean();
flush();
readfile($file);
}else{
die("I'm sorry, this file either does not exist or has been deleted by the user.");
}
?>
<script>
window.close();
</script>
However, if I visit downloadnow.php WITHOUT an ID, such as downloadnow.php?id=612j2dh71, then it downloads the directory.htm, in this case uploads.htm. It's really frustrating, and I hope someone can help me out!
Thanks.