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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.