Jump to content

File Download Help


dennismonsewicz

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.