how to do a download from database using php/mysql
Posted: Thu Jan 21, 2016 3:18 am
hi, i need help from downloading a file on database, i create a download.php and when i press in the button i download a file named index.html, and isn't what i want
this is my code on download.php :
and on the index.php i have this:
if someone can help i will apreciate
thank you
this is my code on download.php :
Code: Select all
<?php
if(isset($_GET['id']))
{
include (config/config.php);
// query the server for the file
$id = $_GET['id_ficheiro'];
$query = "SELECT Ficheiro FROM ficherio WHERE id_ficheiro = '$id'";
$result = mysql_query($query) or die(mysql_error());
// define results into variables
$name=mysql_result($result,0,"Ficheiro");
$size=mysql_result($result,0,"size");
$type=mysql_result($result,0,"type");
$content=mysql_result($result,0,"content");
header("Content-disposition: attachment; filename=$Ficheiro");
header("Content-length: $size");
header("Content-type: $type");
echo $content;
mysql_close();
}
else{
die("No file ID given...");
}
?> Code: Select all
<td><a href='index.php?mod=download&id=$row->id_ficheiro'><button class='btn btn-success'> Download </button></a></td>thank you