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
https://forums.phpfreaks.com/topic/29970-download-file-from-mysql-database/
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
}
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?

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.