So i’m having an upload page where you can add files to a database and the files are saved in “cursuri/” with a varchar insert in a mysql table.
Now i want to download the file but i cant(i checked, the file uploaded is in the folder), i keep getting an empty .htm file instead.
I checked the data from the mysql table preda.material(varchar) and it contains an binary_file.dat and inside it the name of the file.
Now the script:
<?php
session_start();
include_once('scripts/connect_to_mysql.php');
$ID_material = (int) $_GET['ID_material'];
$sql = "SELECT material FROM `preda` WHERE `ID_material` = '$ID_material' ";
$result = mysql_query($sql);
while($info = mysql_fetch_array($result))
{
header("Content-disposition: attachment; filename=". $info['material']);
/* print "Cursuri/".$info['material'] ." <br>"; */
}
?>
This only sets an HTTP header telling the recipient (the browser) that the body of the HTTP response contains file data for a file named XYZ. It does not in itself attach a file or enables the browser to get the file from somewhere. You will still have to output the actual file data yourself. See
readfile.