我在將數據庫寫入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'];
}
*編輯我已經下了數據庫幾次,會導致任何問題?
你是如何得到文件退出? – deceze 2013-05-14 05:32:32
$ songfile的值是多少? – 2013-05-14 05:34:30
@Devin Crossman更好奇它來自哪裏)) – BlitZ 2013-05-14 05:35:07