-1

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 ?

DarthCoder
  • 354
  • 1
  • 11

1 Answers1

-1

LOAD_FILE

Your problem is writing a music file to a blob. $songfile has to be a path to a file on your server

Devin Crossman
  • 7,454
  • 11
  • 64
  • 102
  • yes it sure is ... $songfile points to /tmp/php••••••• i think its a temp file created by the server – DarthCoder May 14 '13 at 05:58
  • if it fails then shouldn't it play nothing at all right ??? – DarthCoder May 14 '13 at 05:59
  • @DarthCoder so it's playing a different song than the one you want? have you checked the value of $fileid is correct? – Devin Crossman May 14 '13 at 06:10
  • Guys solved this ... this happened to be cache problem ... if the response set the content-length but dint return any body. My browser used the older cached result ... after a lot of cross checking .. i lacked permissions to use load_file – DarthCoder May 28 '13 at 21:46