simbu Posted November 26, 2012 Share Posted November 26, 2012 Hello, I want to download a document file from database in phpmyadmin. Here is my codings... <?php if(isset($_GET['id'])) { // if id is set then get the file with the id from database mysql_connect("localhost","root",""); mysql_select_db("sample"); $id = $_GET['id']; $query = "SELECT file FROM testing WHERE id='$id'"; $result = mysql_query($query); list($name) = mysql_fetch_array($result); header("Content-length: ''"); header("Content-type: application/msword"); header("Content-Disposition: attachment; file='$name'"); echo ""; exit; } ?> If i am download , i am getting only empty document . If any one knows let me know.. Link to comment https://forums.phpfreaks.com/topic/271192-how-to-download-a-doc-file-from-database-in-phpmyadmin/ Share on other sites More sharing options...
AyKay47 Posted November 26, 2012 Share Posted November 26, 2012 You are receiving an empty document because you are outputting an empty string. Force a download using readfile Ex: if(file_exists($name)) { header("Content-length: " . filesize($name)); header("Content-type: application/msword"); header("Content-Disposition: attachment; filename=" . basename($name)); ob_clean(); flush(); readfile($name); exit; } else { //file cannot be found } As a side note, your script is vulnerable to SQL injection. Validate $_GET['id'] before using it in a query. Link to comment https://forums.phpfreaks.com/topic/271192-how-to-download-a-doc-file-from-database-in-phpmyadmin/#findComment-1395279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.