Hi, this is my first post:) pretty sure i will be posting here in the future. Anyway i am having trouble with a php script which downloads a file from a mysql database.
This php script works for text files and should work for most files from what i understand. When downloading a text file, the whole file is downloaded from the server. When downloading an mp3 file, only 16kb are downloaded and the file does not play. When looking at the data in the database, it displays that the full file is there (correct amount of bytes, so there is nothing wrong with my upload php script). Does anyone have any suggestions as to what I can change to make this work?
<?php
if(isset($_GET['id']))
{
// if id is set then get the file with the id from database
$link=mysql_connect('localhost', 'root', '');
@mysql_select_db('filemgr') or die ("<p>Could not connect to mysql!</p>");
$id = $_GET['id'];
$query = "SELECT name, type, size, content " .
"FROM upload WHERE id = '$id'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
header("Content-length: $size");
header("Content-type:$type");
header("Content-Disposition: attachment; filename=$name");
echo $content;
mysql_close($link);
exit;
}
?>