duanqi5114 2015-02-23 21:05
浏览 62

如何从数据库下载文件

I want to download file from my uploads table using the attribute sub_name, need help. I have this code of two PHP file one shows the files other downloads it but it's not working.

The uplaods table include sub_name, upload_name, file_content (which is actually the uploaded file) .

My code (the table from which data is sent to be downloaded is):

<?php
    include_once("functions.php");
    $query="SELECT * from uploads";
    $rs = execute_query($query);
?>

<form  action="s_downfinl.php" method="post" enctype="multipart/form-data">
<table border="groove" cellpadding="15px">
<tr>
<td>Subject Name</td>
<td>upload name</td>
<td>Download</td>
</tr>
<?php
    while ($row = mysql_fetch_assoc($rs)){
        echo "<tr><td>";

        echo $row['sub_name']."</td><td>";  
        echo $row['upload_name']."</td>";
        echo "<td><a href='s_downfinl.php?nama=".$file."'>download</a></td>";
    }

    echo "</table>";
?>
</form>

downlaod.php

    <?php
include_once"functions.php()";

$query = "SELECT * FROM uploads WHERE sub_name = $sub_name";
$rs = execute_query($query);
$name= $_GET['nama'];
download($name);

function download($name){
$file = $nama_fail;

if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
}
?>

fuctions.php (for database connection)

<?php
function execute_query($query){
$connection = mysql_connect("localhost","root","");
mysql_select_db("ascs",$connection);
$result_set = mysql_query($query);
mysql_close($connection);
return $result_set;
}
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度