2013-05-14 149 views
-1

我在將數據庫寫入blob(音樂文件)時遇到了問題。當我嘗試和上傳說歌曲(「沒有其他Matter.mp3」)它播放一些其他(我試圖上傳一些時間像songB(「甜的孩子mine.mp3」)...並且它不完全關閉一個)當然,歌曲到服務器是正確的(我已經檢查過)通過播放文件我打印['tmp_name']。Mysql插入到Blob問題

我用這上傳

$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.")"; 

這是我的DBTABLE文件

CREATE TABLE file(
    id INT PRIMARY KEY AUTO_INCREMENT 
    ,contenttype VARCHAR(30) 
    ,file LONGBLOB 
    ,name VARCHAR(30) 
    ,size INT 
)engine=innodb; 

的結構,因爲服務器獲得正確的文件,我認爲故障是與MySQL

通過

下載文件
$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']; 
} 

*編輯我已經下了數據庫幾次,會導致任何問題?

+0

你是如何得到文件退出? – deceze 2013-05-14 05:32:32

+2

$ songfile的值是多少? – 2013-05-14 05:34:30

+0

@Devin Crossman更好奇它來自哪裏)) – BlitZ 2013-05-14 05:35:07

回答

-1

LOAD_FILE

您的問題是寫一個音樂文件到BLOB。 $ songfile必須是你的服務器上的文件的路徑

+0

是的,它肯定是... $ songfile指向/ tmp/php•••••••我認爲它是由服務器 – DarthCoder 2013-05-14 05:58:56

+0

創建的臨時文件,如果它失敗了,那麼它不應該什麼都不起作用對 ??? – DarthCoder 2013-05-14 05:59:18

+0

@DarthCoder所以它播放的歌曲與你想要的不同?你有沒有檢查$ fileid的值是否正確? – 2013-05-14 06:10:50