OK here's my story...
My site allows users to upload files to above the Doc Root
Doc Root is /var/www/html
Upload Dir is /var/www/uploads
Everything is working fine with the exception of getting the files to download via a link.
The database is holding path, file, mime_type, & size
When the user uploads the file, the dbase gets filled in correctly and the file gets uploaded correctly.
Working Upload Script Code
$title = $_REQUEST['title'];
$client = $_REQUEST['client'];
$time = time();
$upload_dir = '/var/www/uploads/';
$file_name = ($_FILES['userfile']['name']);
$filesize = $_FILES['userfile']['size'];
$filetype = $_FILES['userfile']['type'];
$query = "insert into depot
(title, client, path, file, mime_type, size, user, created)
values
('$title', '$client', '$upload_dir', '$file_name', '$filetype', '$filesize', '".
$_SESSION['auth_user']."', $time)";
$result = $handle->query($query);
if (!$result)
{
echo "There was a database error when executing <pre>$query</pre>";
echo mysqli_error();
exit;
}
if ( (isset($_FILES['userfile']['name']) &&
is_uploaded_file($_FILES['userfile']['tmp_name'])))
{
$filename = $upload_dir.$file_name;
move_uploaded_file($_FILES['userfile']['tmp_name'], $filename);
}
header('Location: '.$_REQUEST['destination']);
My link to get users to the download script is simply
echo "<a href='download.php?id={$depot['id']}'>
{$depot['title']}<br />
</a>";
Download Script is where I'm having the problems...
<?php
include_once('db_depot.php');
$id = $_GET['id'];
$query = "select file, type, size, path from depot where id = '$id'";
$result = $handle->query($query)
if (!$result)
{
echo "There was a database error when executing <pre>$query</pre>";
echo mysqli_error();
exit;
}
$filename = '$file';
$filetype = '$mime_type';
$filepath = $path . $filename;
if (!file_exists($filepath)) {
die('SORRY!, <b>' . $filepath . '</b> could not be found.');
} else {
header('Content-type: ' . $filetype);
header('Content-Disposition: attachment; filename="' . $filename . '"');
readfile($filepath);
}
}
?>
And I just can't figure it out.
Hoping another eye might catch I'm missing, or somethin' I'm just plain wrong with.