不开放,我有两个PHP文件
1 List_files - >显示所有上传的文件
2. Get_file - >从列出的文件下载文件...下载的文件格式正确
现在,当我下载任何图像或任何文本文件,并尝试打开它不会被打开,
错误是格式不支持每次。
我的形象.JPEG
我使用Windows Vista,和Firefox。
在下载没有问题,问题出在打开文件..
get_file.php
<?php
// Make sure an ID was passed
if(isset($_GET['id']))
{
// Get the ID
$id = intval($_GET['id']);
// Make sure the ID is in fact a valid ID
if($id <= 0)
{
die('The ID is invalid!');
}
else
{
// Connect to the database
$con=mysql_connect("localhost","root","");
if(!$con)
{
die('Could Not Connect:'.mysql_error());
}
mysql_select_db("tcs",$con);
// Fetch the file information
$query = "SELECT `mime`, `name`, `size`, `data` FROM `file` WHERE `id` = {$id}";
$result=mysql_query($query,$con);
if($result)
{
$count = mysql_num_rows($result); // Make sure the result is valid
if($count == 1)
{
// Get the row
$row = mysql_fetch_array($result);
// Print headers
header("Content-Type: ".$row['mime']);
header("Content-Length: ".$row['size']);
header("Content-Disposition: attachment; filename=".$row['name']);
// Print data
echo $row['data'];
}
else
{
echo 'Error! No image exists with that ID.';
}
// Free the mysqli resources
//mysql_free_result($result);
}
else
{
echo "Error! Query failed: <pre>".mysql_error()."</pre>";
}
mysql_close();
}
}
else
{
echo 'Error! No ID was passed.';
}
?>
你应该在这里显示get_files而不是list_files。 – 2010-01-26 12:30:01
哦,我现在是我soory显示正确的文件 – 2010-01-26 15:46:21
您是否尝试用记事本打开文件?它发生在我身上,而所有被保存的内容都是警告和错误。 – Dolfa 2010-01-26 12:35:04