由于某种原因,我点击了网址进行下载后,碰巧在我的浏览器上查看该文件会导致大量符号和随机字母。有没有办法让它下载而不是在浏览器上查看?我真的很喜欢编程,你的指导会很有帮助。谢谢。
<?php
mysql_connect("localhost","root","");
mysql_select_db("tuitioncentre");
if(isset($_GET['id'])) { // if id is set then get the file with the id from database
$id = $_GET['id'];
$query = "SELECT name, type, size, content FROM files WHERE id = $id";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) =
mysql_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content; exit;
}
?>
<?php
$query = "SELECT id, name FROM files";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))
{
?>
<a href="download2.php?id=<?php echo $id;?>"><?php echo $name; ?></a>
<?php
}
}
&GT;