dennismonsewicz Posted March 19, 2008 Share Posted March 19, 2008 I am using the following script to access downloadable files: <?php if(isset($_GET['id'])) { // if id is set then get the file with the id from database include "includes/sql.php" $id = $_GET['id']; $query = "SELECT name, type, size, url " . "FROM uploads WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $url) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$name"); echo $url; exit; } ?> Now the problem is this: When I click on the link to run this script the "file" is passed through the URL for download, but no actual file comes through. Any suggestions? Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 19, 2008 Share Posted March 19, 2008 have you tried debugging it at all? are all the variables what you would expect? what type of files are you trying to transact? Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted March 19, 2008 Author Share Posted March 19, 2008 Lets see if I can explain this a little better. I have a php file called myphotos.php, within this file the images (jpgs, gifs, pngs, etc...) that a particular user has uploaded are shown. When the user clicks on download image I need for the script to pull the file out of a directory called imageuploads and thus sending the file to the user via the URL. Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted March 19, 2008 Author Share Posted March 19, 2008 I figured out: at the end of the script I inserted the following: readfile($name); and it worked! Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 19, 2008 Share Posted March 19, 2008 lol sorted Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 19, 2008 Share Posted March 19, 2008 is the echo($url) necessary? is it the actual url or the image binary content? Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted March 19, 2008 Author Share Posted March 19, 2008 the echo($url) actually doesn't do anything LOL I took it off of my updated script, here it is: <?php if(isset($_GET['id'])) { // if id is set then get the file with the id from database include "../includes/sql.php"; $id = $_GET['id']; $query = "SELECT name, type, size " . "FROM uploads WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$name"); readfile($name); exit; } ?> **SIDENOTE: your download.php file must be in the same directory as your uploaded files (at least for this script to work) Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 19, 2008 Share Posted March 19, 2008 thought it would be something like this, since you were giving the contents of $url isntead of the contents of the image requested Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted March 19, 2008 Author Share Posted March 19, 2008 Yeah, I don't know what I was thinking... I am just really glad the script works! Quote Link to comment 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.