I have a internal website which user log in and upload files , I am about to publish this site to the outside clients on the webserver so I don't have the files being uploaded below the webroot.
Docroot is /var/www/html/
I have the uploads directory set to /var/www/uploads/
I can get the files to upload successfully; however, when I provide a link to the files via the code below
echo "<a href='download.php?id={$uploads['id']}'>
{$uploads['title']}<br />
</a>";
The user clicks on the link and all SEEMS good, a file dialog box appears prompting download with the correct filename; however, the file is always blank or only shows the header info sent by the download script I created (shown below).
<?php
include_once('db_depot.php');
$handle = db_connect();
$file = $_GET['id'];
$query = "select id, path, file, type, size from uploads where id = $file";
$result = $handle->query($query);
if (!$result)
{
echo "There was a database error when executing <pre>$query</pre>";
echo mysqli_error();
exit;
}
if ($file = $result->fetch_assoc())
{
$file = $file['file'];
$type = $file['type'];
$size = $file['size'];
$path = $file['path'];
$filepath = $path . $file;
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header( "Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=""$_SERVER['DOCUMENT_ROOT']../fileshare/$file");
header( "Content-Description: File Transfer");
header('Accept-Ranges: bytes');
header('Content-Length: ' . $filesize);
@readfile("$_SERVER['DOCUMENT_ROOT']../fileshare/$file");
}
exit;
?>
Can anyone out here help??
Thx