【发布时间】:2021-12-12 03:12:59
【问题描述】:
我尝试使用此代码从我的数据库中下载文件,但是,当我尝试打开文件时,出现以下错误:
下载文件类型“图像”时:
下载文件类型“docx”时:
php代码:
<?php
include_once 'dbconfig.php';
if (isset($_GET['id'])) {
$id = $_GET['id'];
$query = "SELECT * FROM files_data WHERE id = '$id'";
$result = mysqli_query($connection,$query) or die('Error, query failed');
list($id, $file, $type, $size,$content) = mysqli_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$file");
$content = stripslashes($content);
echo file_get_contents($content);
exit;
}
?>
数据库:
Word 文档的存储类型为:“application/vnd.openxmlformats-officedocument.wordprocessingml.document”(在屏幕截图中不可见)。我相信这是正确的
【问题讨论】:
-
请edit这个问题输入图像中的文本,以便可以在所有设备上阅读、引用、编辑和通过搜索找到它。就目前而言,your image makes it hard to answer your question or for people with related issues to find your question。请参阅formatting documentation 以获取在不借助图像的情况下使您的文本看起来很漂亮的提示。