我试图从我的数据库下载文件,然后我将php文件作为输出返回。但是当我使用var_dump时,我能够得到如图1所示的输出
和图2.
我希望能够将该文件下载为其实际文件类型。 (即作为pdf)任何人都可以帮我这个吗?在此先感谢:)
这是我的下载代码:
scope :only_public, -> { where(privacy: false) }
scope :only_private, -> { where(privacy: true) }
这是调用处理数据库的函数的地方:
try {
//if id is set then get file from database
if (isset($_GET['id'])) {
$id = $_GET['id'];
//pump id into function getDBFiles to pull file with matching id
$Download->getDBFiles($id);
//get array containing file details from function getDBFiles
$getFiles = $Download->getMessages();
//var_dump($getFiles);
$size = $getFiles['size'];
$type = $getFiles['type'];
$name = $getFiles['name'];
$content = $getFiles['content'];
header("Content-length: ".$size.'"');
header("Content-type: application/vnd.openxmlformats");
error_reporting(0);
header('Content-Disposition: attachment; filename="' . $name . '"');
echo $content;
exit;
}
//execute retrieval of files from database
$Download-> showDBFiles();
//pass results to output array
$output = $Download->getMessages();
//var_dump($output);
} catch (Exception $e) {
$result[] = $e->getMessages();
}