I need to print out all the files that I\'ve saved in a database and then make it possible to download them. I am able to echo them, but I don\'t know how to make a download \"b
I once made a similar script, what you have to do is set some headers and echo the data from database.
An example of that could be, assuming that the data is in $row['filedata'], the following
Now you have to know what file to download first, and for that we can use a GET or POST parameter
1 || $result_check < 1){ //If more then 1 result die
die('inavlid ID');
}
$row = mysqli_fetch_assoc($result);
//and here the above mentioned lines
?>
The easiest way to add a download button to the page would be by using the window.open() function in JavaScript like so:
echo $row['Ime']."
";
This will open a new window which will download the file
The total would look something like this For download.php:
1 || $result_check < 1){ //If more then 1 result die
die('inavlid ID');
}
$row = mysqli_fetch_assoc($result);
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=".$row['Ime']);
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
echo $row['filedata'];
?>
and for index.php
0){
while($row = mysqli_fetch_assoc($result)){
echo $row['Ime']."
";
}
}
?>