I want to upload a .wav files as blob to database. I do not want to upload it to a directory.
I think I have successfully uploaded the file as blob to database, but when I want to download the file, it downloads a plain file without extension name. I was expecting something like .wav as the file extension etc.
Here is my table
create table content(
id int primary key auto_increment,
cid int(11),
data_file varchar(200),
data longblob);
alter table content add column(
name1 varchar(200),
type1 varchar(200),
size1 varchar(200));
Here is the code for upload
<?php
if(isset($_FILES['file']) and !$_FILES['file']['error']){
echo $tt= strip_tags($_POST['idb']);
//$fname = "155" . ".wav";
$fname = time() . ".wav";
$tmpName = $_FILES['file']['tmp_name'];
$name = $_FILES['file']['name'];
//move_uploaded_file($_FILES['file']['tmp_name'], "uploads/" . $fname);
include('db.php');
$type1= $_FILES["file"]["type"];
$size1=$_FILES["file"]["size"];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
$statement = $db->prepare("INSERT INTO content (cid,data_file,data,name1,type1,size1) values
(:cid,:data_file,:data,:name1,:type1,:size1)");
$query= $statement->execute(array(
':cid' => $tt,
':data_file' => $fname,
':data' => $content,
':name1' => $name,
':type1' => $type1,
':size1' => $size1
));
fclose($fp);
// move_uploaded_file($_FILES['file']['tmp_name'], "./uploads/" . $fname);
}
?>
Here is the code for download
<?php
include('db.php');
$result = $db->prepare('SELECT * FROM content');
$result->execute(array());
$count = $result->rowCount();
while($row = $result->fetch()){
$content=htmlentities($row['data']);
$name=htmlentities($row['name1']);
$type=htmlentities($row['type1']);
$size=htmlentities($row['size1']);
$bb=htmlentities($row['bb']);
}
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;
?>
Can someone help me fix the issue of not been able to download the .wav files from database?