2013-05-14 151 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