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? Link to comment https://forums.phpfreaks.com/topic/96869-file-download-help/ 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? Link to comment https://forums.phpfreaks.com/topic/96869-file-download-help/#findComment-495713 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. Link to comment https://forums.phpfreaks.com/topic/96869-file-download-help/#findComment-495715 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! Link to comment https://forums.phpfreaks.com/topic/96869-file-download-help/#findComment-495719 Share on other sites More sharing options...
uniflare Posted March 19, 2008 Share Posted March 19, 2008 lol sorted Link to comment https://forums.phpfreaks.com/topic/96869-file-download-help/#findComment-495720 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? Link to comment https://forums.phpfreaks.com/topic/96869-file-download-help/#findComment-495721 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) Link to comment https://forums.phpfreaks.com/topic/96869-file-download-help/#findComment-495722 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 Link to comment https://forums.phpfreaks.com/topic/96869-file-download-help/#findComment-495731 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! Link to comment https://forums.phpfreaks.com/topic/96869-file-download-help/#findComment-495736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.