I have several files stored in a database and I have a script to download those files. Everything works great with plain text files but with anything else (pdf, jpeg, doc, etc...) I just get a lot of junk. I'm guessing its showing me the plain text version of a file that is encoded to open with an application. I am including the script I am using to get the files....any help would be greatly appreciated.
<?php
if(isset($_GET['id']))
{
// connect to the database
include "connect.php";
// query the server for the file
$id = $_GET['id'];
$query = "SELECT * FROM upload WHERE id = '$id'";
$result = mysql_query($query) or die(mysql_error());
// define results into variables
$name=mysql_result($result,0,"name");
$size=mysql_result($result,0,"size");
$type=mysql_result($result,0,"type");
$content=mysql_result($result,0,"content");
header("Content-disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
echo $content;
mysql_close();
}
else{
die("No file ID given...");
}
?>
hi, i try to use your code, to download a file, but when i try to do a download, i download a file name index.php, no the file i want, so if you can help me i will appreciate it