Jump to content

Download File From mysql Database


papaface

Recommended Posts

Hello,
I was wondering if someone could help me.
Currently I have the following code:
download.php
[code]
<?php
require("connect.php");
require("dbselect.php");

$id = $_GET['id'];

$selectfrmdb = "select name,type,size,upload "."from uploads where upID = '$id'";

$result = mysql_query($selectfrmdb,$con)or die('Error, query failed');

list($name,$type,$size,$upload) = mysql_fetch_array($result);

header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $upload;


mysql_close($con);
exit;
?>[/code]

When I go to download.php?id=1 i get prompted to save a file called download.php instead of the filename or file that I want to download from the database.
If you need anymore information in order to help me with this let me know.
Thanks
Link to comment
Share on other sites

Well a couple of things come to mind here.

1.  Is PHP installed correctly?  I'm sure it is but, well, it happens.  Can you view any other PHP enabled pages?
2.  WOrking on a download script I had this happen once as well.  It ended up being due to a bad path.  From what you posted there it looks as if you're trying to download from the same directory as the file.  Try throwing a few conditionals in there to help diagnose the issue...

if (!file_exists($file)) {
  echo 'not found';
} else {
  //download
}
Link to comment
Share on other sites

One thing I've noticed is that if a script gets executing for a very long time, well not sure how long but.. anyway it prompts me to download the script and not the information I wanted.

Perhaps the file that you're pulling from the database is too large for your php.ini files to handle in script execution time?

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.