I am working in a project where I store files in Mysql database.
I stored the files as long blob in my database and I want to make them readable in my site web based on PHP. I tried to view PDF files and it works but if I try to download Excel File, it gives me file.php and some numbers.
//PHP
$dbh= new PDO("mysql:host=localhost;dbname=smi","root","");
$id=isset($_GET['id_fichier'])? $_GET['id_fichier']:"";
$stat=$dbh->prepare("select * from fichier where id_fichier=?");
$stat->bindparam(1,$id);
$stat->execute();
$row=$stat->fetch();
$file = $row['fichier'];
$type=$row['type'];
header('Content-Type:'.$type);
echo($file);
I expect the excel file but I get something like this.
3c21 444f 4354 5950 4520 6874 6d6c 3e0d
0a3c 6874 6d6c 2064 6972 3d22 6c74 7222
206c 616e 673d 2265 6e22 3e0d 0a3c 6865
6164 3e0d 0a3c 7469 746c 653e 534d 4920
4165 726f 706f 7274 2046 6573 2053 6169
7373 3c2f 7469 746c 653e 0d0a 0d0a 3c2f