Download Links (1 viewing) (1) Guest
Favoured: 0
|
|
|
TOPIC: Download Links
|
mdub (User)
Junior Boarder
Posts: 26
|
|
Download Links 1 Year, 12 Months ago
|
Karma: 5
|
I've got an internal site to which users log in and then can 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
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
dan (Admin)
Admin
Posts: 179
|
|
|
|
|
|
|
I wouldn't recommend sex- drinks- or Mac for everyone but they work for me.
Programming Help, OS System Help, Articles, Videos, Tutorials, Books-Web Dot Dev http://www.webdotdev.com
|
|
|
The administrator has disabled public write access.
|
dan (Admin)
Admin
Posts: 179
|
|
Re:Download Links 1 Year, 12 Months ago
|
Karma: 5
|
well maybe this will help you out.
i have took a break from my web site so I thought to do a research and see if I can help you out with your web site.
try to do this , to debug
get rid of all your calls to header()
start using var_dump() on all your variables so you can see thier values.
dont silence errors with the @ char
turn up error reporting
PHP Code:
| Code: |
// top of your scripts
ini_set('display_errors', 1);
error_reporting(E_ALL);
|
if you have any problems let me know.
dan,
|
|
|
|
|
|
|
I wouldn't recommend sex- drinks- or Mac for everyone but they work for me.
Programming Help, OS System Help, Articles, Videos, Tutorials, Books-Web Dot Dev http://www.webdotdev.com
|
|
|
The administrator has disabled public write access.
|
mdub (User)
Junior Boarder
Posts: 26
|
|
Re:Download Links 1 Year, 11 Months ago
|
Karma: 5
|
OK, Got the error reporting set (sheesh, that helped out a bit).
I'm a little confused on how I'd use the var_dump()
I have the variables set...
| Code: |
while ($file = $result->fetch_assoc())
{
$theFile = $file['name'];
$type = $file['type'];
$size = $file['size'];
//$path = $file['path'];
if(!is_readable($theFile))
{
die("$contents does not exist or is not readable"«»);
}
else
{
var_dump($filename);
}
}
?>
|
Now, it does come out to the browser and shows what the variable should be ....
string(23)"/var/www/uploads/file.doc"
But that's all. However, I do like the idea of using that var_dump() to diagnose problems. OR is that what I should be using it for here.
IF I change out the var_dump() for readfile($theFile).
Then it basically dumps the contents of the file to the browser; however, then the contents are all garbled on screen (and I'd like to force the download).
Anymore ideas? HELllppPPP MEeeEE 
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
dan (Admin)
Admin
Posts: 179
|
|
Re:Download Links 1 Year, 11 Months ago
|
Karma: 5
|
well, you had a couple parse errors in the origional code.
here
| Code: |
header( "Content-Disposition: attachment; filename=""$_SERVER['DOCUMENT_ROOT']../fileshare/$file"«»);
|
and here
| Code: |
@readfile("$_SERVER['DOCUMENT_ROOT']../fileshare/$file"«»);
|
it looked like once you fixed those, it could probably work.
in your latest code you have created a new variable named $theFile. so you have changed your code in more ways than i can assume. so, whats it look like now? when you add the headers back in, what happens?
although this shouldnt cause it not to work, you probably dont want the accept-ranges: bytes header unless you plan to implement serving byte range requests. if not, send "none" instead of "bytes"
|
|
|
|
|
|
|
I wouldn't recommend sex- drinks- or Mac for everyone but they work for me.
Programming Help, OS System Help, Articles, Videos, Tutorials, Books-Web Dot Dev http://www.webdotdev.com
|
|
|
The administrator has disabled public write access.
|
mdub (User)
Junior Boarder
Posts: 26
|
|
Re:Download Links 1 Year, 11 Months ago
|
Karma: 5
|
I have changed it quite a bit.
Changed all of the pages a bit actually.
Now have
| Code: |
ini_set('display_errors', 1);
error_reporting(E_ALL);
|
up top of all the pages. Sure does help out a bunch. Had to take a break from coding that download link for my sanity  and figured I'd get more 'looks' on to the page.
GRRR, come in this morning and open up the page and all sorts of wonky stuff goin' on.
Open the index.php page, login and get
Notice: Trying to get property of non-object in /var/www/html/sandbox/cafs/index.php on line 33 on my page.
Seems like the issue is $uploads_result->num_rows
But it is there...
| Code: |
if (!check_auth_user())
{
login_form();
}
else
{
$handle = db_connect();
$user = get_user_record($_SESSION['auth_user']);
$uploads_sql = "select *
from user_permissions, uploads, clients
where user_permissions.username = '{$_SESSION['auth_user']}'
and uploads.client = clients.code
and clients.code = user_permissions.company";
$uploads_result = $handle->query($uploads_sql);
echo '<p align="center">Welcome to the Enviromental Monitoring & Technologies Client Access File Sharing System</p>';
echo $user['fullname'].' You have access to ' . $uploads_result->num_rows . ' records. (<a href="admin/file.php">Add New</a>«») OR'.
|
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
|
|
|
|
|
|
Who's Online |
|
We have 1 guest online |
|