将 blob(音乐文件)写入数据库时遇到问题。当我尝试上传歌曲A(“Nothing else Matter.mp3”)时,它会播放其他歌曲(我之前尝试上传的歌曲B(“我的Sweet Child of mine.mp3”)...减一)当然,通过播放文件我打印['tmp_name'],进入服务器的歌曲是正确的(我已经检查过了)。
我用这个来上传
$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'];
}
*编辑我已经多次删除数据库,这会导致任何问题吗?