【发布时间】:2013-12-13 18:04:39
【问题描述】:
我正在尝试在浏览器上查看存储在数据库中的文件(即:excel 表格/pdf/图像)。
我已经编写了一个从数据库下载文件的代码,它正在运行,但我想在浏览器中显示它。
代码如下:
<?php require_once('Connections/databasestudents.php'); ?>
<?php
$id = $_GET['id']; // ID of entry you wish to view. To use this enter "view.php?id=x" where x is the entry you wish to view.
$query = "SELECT fileContent, filetype FROM file where id = $id"; //Find the file, pull the filecontents and the filetype
$result = MYSQL_QUERY($query); // run the query
if($row=mysql_fetch_row($result)) // pull the first row of the result into an array(there will only be one)
{
$data = $row[0]; // First bit is the data
$type = $row[1]; // second is the filename
Header( "Content-type: $type"); // Send the header of the approptiate file type, if it's' a image you want it to show as one :)
print $data; // Send the data.
}
else // the id was invalid
{
echo "invalid id";
}
?>
发生的情况是 view.php 被下载,但没有查看任何内容。
有什么建议吗?
【问题讨论】:
-
PHP 在您的网络服务器上配置不正确,或者没有安装。
-
我所有其他的 php 页面都可以工作!我下载了自动安装 php、sql 和 apache 的 wamp 服务器
标签: php mysql sql browser view