MySQL Forums
Forum List  »  PHP

Download in PHP
Posted by: Ng Py
Date: April 07, 2006 02:46AM

Hi,

I am newbie in PHP and currently working for an e document management systems. I faced some problem in the download coding that i did. The problems are:

1. After i uploaded a document, i click on the link, it will open automatically, without let user to save that file.
2. Only .txt file can be open and all the characters can be see and read clearly. Other file types such as .doc, .jpg, it only can see those weird characters.

Is that anything wrong with my download codes below?

<?php
error_reporting(E_ALL);
if(isset($_GET['id']))
{
include 'db_connect.php';

$id = $_GET['id'];
$query = "SELECT name, type, size, path FROM upload2 WHERE id = '$id'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $filePath) = mysql_fetch_array($result);

// header("Content-Disposition: attachment; filename=$name");
// header("Content-length: $size");
// header("Content-type: $type");

readfile($filePath);

exit;
}

?>

<html>
<head>
<title>Download File From MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="" method="post" name="form1" target="_self">
<?php
include 'db_connect.php';

$query = "SELECT id, name FROM upload2";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))
{
?>
<a href="download.php?id=<?=$id;?>"><?=$name;?></a> <br>
</a> <br>
<?php
}
}

?>
</form>
</body>
</html>

Please help me out if anyone knows where is the problem, thanks alot.

Options: ReplyQuote


Subject
Written By
Posted
Download in PHP
April 07, 2006 02:46AM
April 07, 2006 09:12AM
April 08, 2006 02:27AM
April 08, 2006 08:54AM
April 09, 2006 07:56AM
April 09, 2006 01:02PM
April 11, 2006 09:05AM
April 11, 2006 09:16AM
April 22, 2006 08:03AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.