-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 ?

13
  • And how are you getting the files back out? Commented May 14, 2013 at 5:32
  • 2
    what is the value of $songfile? Commented May 14, 2013 at 5:34
  • @Devin Crossman more curious where it came from)) Commented May 14, 2013 at 5:35
  • @deceze I have edited the question ... but it shouldn't play anything at all right ??? why is it acting that weird ??? if it doesn't play ... i can assume that the load had some problems !! Commented May 14, 2013 at 5:40
  • @DevinCrossman i have added the line that defines $songfile sorry about that Commented May 14, 2013 at 5:41

1 Answer 1

-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

Sign up to request clarification or add additional context in comments.

4 Comments

yes it sure is ... $songfile points to /tmp/php••••••• i think its a temp file created by the server
if it fails then shouldn't it play nothing at all right ???
@DarthCoder so it's playing a different song than the one you want? have you checked the value of $fileid is correct?
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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.