file download issue
Posted: Tue Sep 02, 2003 12:55 pm
I need to find out whats wrong with this code and nuthin is being displayed on the page ..... it wud be a great help.... thanks
Code: Select all
<?php
@MYSQL_CONNECT("localhost","root","dbstuff3r");
@mysql_select_db("extranet");
$self=$_SERVER['PHP_SELF'];
if (isset($_GET['id']))
{
$id=$_GET['id'];
$query = "select file_data, id,name,file_type,file_size,downloads from files where id='$id'";
@$result = MYSQL_QUERY($query);
$row=mysql_fetch_array($result);
$type = $row["file_type"];
$name= $row["name"];
$size= $row["file_size"];
$id= $row["id"];
$data= urldecode($row["file_data"]);
$downloads=$row["downloads"];
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
die;
}
else{
$query = "select id,name,file_type,file_size,downloads from files";
$result = MYSQL_QUERY($query) or die("Can't execute!".mysql_error());
$table="<table summary="files" border=1>"
."<tr bgcolor="#ffffcc"><td>File name</td><td>Size</td><td>File Type</td><td>Download</td><td>Downloads</tr>";
while($row=mysql_fetch_array($result) )
{
$type=$row["type"];
$name=$row["name"];
$size=$row["file_size"];
$id=$row["id"];
$downloads=$row["downloads"];
$table .="<tr><td>$name</td><td>$size</td><td>$type</td><td><a href="$self?id=$id">Download </a><td>$downloads</td></td>";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Download</title>
</head>
<body>
<center><h1> Choose a file to download</h1>
<?echo $table?>
</center>
</body>
</html>