I have a problem when it comes to write the blob (a music file) on to the database. When i try and upload say songA("Nothing else Matter.mp3") it plays some other (the one that i tried to upload some time earlier like songB("Sweet Child of mine.mp3")... and its not exactly off by one) of course the song that goes to the server is the right ( i have checked that ) by playing file i printing the ['tmp_name'].
i am using this to upload
$contenttype = $_FILES['song']['type'];
$songfile = $_FILES['song']['tmp_name'];
$size = $_FILES['song']['size'];
$query = "INSERT INTO file(contenttype,file,size) values('".$contenttype."',LOAD_FILE('$songfile'),".$size.")";
this is the structure of my dbtable file
CREATE TABLE file(
id INT PRIMARY KEY AUTO_INCREMENT
,contenttype VARCHAR(30)
,file LONGBLOB
,name VARCHAR(30)
,size INT
)engine=innodb;
Since the server is getting the right file, I assumed that the fault is with mysql
file download through
$query = "SELECT * FROM file WHERE id=$fileid";
$res = mysql_query($query,$connection) or die("$fileid Error ".mysql_error());
if(!$res){
$status = false;
error_log("fileid: ".$fileid);
$response = new Tonic\Response(Tonic\Response::OK); //using tonic shouldn't matter
}else{
$tres = mysql_fetch_assoc($res);
$response = new Tonic\Response(Tonic\Response::OK);
$response->contentType=$tres['contenttype'];
$response->contentLength=$tres['size'];
$response->contentTransferEncoding='binary';
error_log('Length: '.strlen($tres['file'])); //strangely this is zero ?? but how is it even playing ??
$response->body = $tres['file'];
}
*EDIT i have droped the database a several times, will that cause any problems ?