mdub2112 Posted December 6, 2006 Share Posted December 6, 2006 OK here's my scenario...I've got an Intranet site to which I have users uploading files to a folder above the docroot via PHP/MySQL.Docroot is /var/www/htmlUpload folder is /var/www/uploadsOnce the user fills out the form, of course, items such as id, title, path, file, type, and size are then set in the dbase. That all works.The link I'm using to provide a download link isPHP Code:[code=php:0]echo "<a href='download.php?id={$depot['id']}'> {$depot['title']}<br /> </a>";[/code][b]My download.php script is as followsPHP Code:[/b][code=php:0]<?PHPinclude_once('db_depot.php');$handle = db_connect();$file = $_GET['id'];$query = "select id, path, file, type, size from depot 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('Content-type: ' . $type); header('Content-Disposition: attachment; filename="' . $file . '"'); readfile($filepath); }exit;?>[/code]Now, everything SEEMS to work; however, even though the file download has the correct name, it appears more as if the system is creating a file on the fly using the filename from the dbase instead of sending the file that is in the uploads folder. I'll click a link to download a file that I know is an image and open it up with MS Image Viewer and it comes up with "No preview available". MS Word or Excel files come up all garbled and the only readable information I get from them is the header info.What's Am I doin' wrong? Can I download files from a folder above the docroot?If not, has anyone ever used the database to store the files (don't want the files to get uploaded to a location viewable by everyone as this will eventually go on the web for client use. Is there anyone that can give me a hand with this? Quote Link to comment https://forums.phpfreaks.com/topic/29740-download-links/ Share on other sites More sharing options...
Daniel0 Posted December 7, 2006 Share Posted December 7, 2006 Try to look at this http://www.phpfreaks.com/forums/index.php/topic,95433.0.html :) Quote Link to comment https://forums.phpfreaks.com/topic/29740-download-links/#findComment-136552 Share on other sites More sharing options...
mdub2112 Posted December 7, 2006 Author Share Posted December 7, 2006 While waiting on hopeful replies, I had done further searching these forums and found a link to that thread.I changed my code to basically match; however, I'm getting the same exact results I had prior.Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/29740-download-links/#findComment-136554 Share on other sites More sharing options...
mdub2112 Posted December 7, 2006 Author Share Posted December 7, 2006 Can anyone help me with this? Quote Link to comment https://forums.phpfreaks.com/topic/29740-download-links/#findComment-137003 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.