2016-02-18 41 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 ^^