2016-02-18 42 views
1

我插入音频文件到我的数据库,我是retreiving他们就好了,然后一些文件只是不会检索即使我使用相同的代码这里的代码 getAudio .PHP无法从数据库检索longblob音频文件

<?php 
include 'conn.php'; 
// to connect with the database 
    $id = $_GET['id']; 
    // validation just to be safe 

    $sql = "SELECT file FROM letters1 WHERE id=$id"; 
    // choose the column from the table where the id= the id of the audio file 

    $result = mysql_query("$sql"); 
    //query the audio file 

    $row = mysql_fetch_assoc($result); 
    //Returns an associative array 

    mysql_close($link); 
    //closes the non-persistent connection to the MySQL 

    header("Content-type: audio/mpeg"); 
    //audio/wav for wav files mpeg for mp3 files, we used mp3 cuz 
    //wav didn't work on IE so just to be sure 

echo $row['file']; 
//calls the audio file and returns it in the src attribute 
?> 

returnblobfile.php

<?php include 'php/conn.php' 
?> 

<!DOCTYPE html> 
<head><title>new</title></head> 
<body> 
<audio controls> 
<source src="php/getAudio.php?id=14" type="audio/mpeg"> 
</audio> 

</body> 
</html> 

我使用phpMyAdmin的它停在ID 14,16,19,20,他们是不是空的我一直在编辑它们。 请帮助..在此先感谢

+0

你很容易受到[sql注入攻击](http://bobby-tables.com)的影响,并且只是假设你的查询成功了。从来没有** EVER **假设数据库操作成功。总是假设失败,检查失败,并将成功视为令人惊喜的事情。 –

回答

0

SQL注入一边,你的代码似乎没问题。可能是你达成一些内存或存储限制:

  • 猜想1:您正在使用BLOB类型字段,但您的文件比更大,当插入到表被截断。使用具有更多容量的字段类型可能是一种解决方案(mediumblob或longblob)。

  • 猜测2:file字段的内容对于php内存限制来说太重了。你可以用这样的尝试让更多:

使用和.htaccess文件:

php_value memory_limit 128M 

或者使用的ini_set在脚本的顶部:

ini_set('memory_limit', '128M'); 

(32, 64,128或任何数字适合你)

编辑:哎呀...没有注意,标题显示y说你正在使用longblob ^^