正确连接数据库,当我尝试下载文件时,我得到的内容是我正在处理的这个文件的php页面。而不是上传到数据库的文件。为什么会这样?
button
答案 0 :(得分:0)
修改您的代码
while ( (list($id, $name) = mysqli_fetch_array($result, MYSQLI_BOTH)){echo $name . " " . $id. " " ."<a href=download.php?id=$id>$name</a><br>"; }
在download.php中使用
if(isset($_GET['id'])){
$id = $_GET['id'];
$query = "SELECT id, name, type, size, content FROM docu WHERE id = '$id'"; $result = mysqli_query($link, $query);$row = mysqli_fetch_array($result, MYSQLI_BOTH);$size = $size;$type = $type;$name =$name;header("Content-length: $size");header("Content-type: $type");header("Content-Disposition: attachment; filename=$name");}mysqli_close($link);