download issue
Posted: Tue Sep 02, 2003 5:12 pm
I need to know the mistakes with this code. It is supposed to download the required file based on id number but instead of downloading the file in the database, it gives the user the option to download download.php which is the file in which the script is present in and not the required file from the DB
<html>
<head><title>Download Page</title></head>
</html>
<?php
//connecting to the database
@ $db = mysql_pconnect("localhost", "root", "dbstuff3r");
//connection error
if(!$db)
{
echo "error could not connect to the database. please try again later";
exit;
}
//selecting database
mysql_select_db("extranet");
if ($id)
{
$query = "select file_data,name,file_type,file_size,downloads from files where id=$id";
$result = mysql_query($sql);
$data = @mysql_result($result, 0, "file_data");
$name = @mysql_result($result, 0, "name");
$size = @mysql_result($result, 0, "file_size");
$type = @mysql_result($result, 0, "file_type");
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
readfile($name);
echo $data;
die;
}
<html>
<head><title>Download Page</title></head>
</html>
<?php
//connecting to the database
@ $db = mysql_pconnect("localhost", "root", "dbstuff3r");
//connection error
if(!$db)
{
echo "error could not connect to the database. please try again later";
exit;
}
//selecting database
mysql_select_db("extranet");
if ($id)
{
$query = "select file_data,name,file_type,file_size,downloads from files where id=$id";
$result = mysql_query($sql);
$data = @mysql_result($result, 0, "file_data");
$name = @mysql_result($result, 0, "name");
$size = @mysql_result($result, 0, "file_size");
$type = @mysql_result($result, 0, "file_type");
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
readfile($name);
echo $data;
die;
}