files wont open | Member | | Join Date: Mar 2007
Posts: 77
| | |
I have a download script which holds files which have been uploaded by the users.. the files are shown on this page but once i try to open them, nothin happens...any1 help
script
[PHP]<?php require_once('Connections/mysql_connect.php'); ?>
<?php
if(isset($_GET['name']))
{
$name = $_GET['name'];
$query = "SELECT type, size, content FROM uploadfiles WHERE name = '$name'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
echo $content;
exit;
}
mysql_select_db($database_mysql_connect, $mysql_connect);
$query_Recordset1 = "SELECT * FROM uploadfiles";
$Recordset1 = mysql_query($query_Recordset1, $mysql_connect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_free_result($Recordset1);
?>
<html>
<head>
<title>Download File From MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
$query = "SELECT name FROM uploadfiles";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty
";
}
else
{
while(list($name) = mysql_fetch_array($result))
{
?>
<a href="download.php?id=<?=$id;?>"><?=$name;?>[/url]
<?
}
}
?>
</body>
</html>[/PHP]
| | Newbie | | Join Date: Jul 2008
Posts: 4
| | | re: files wont open
[PHP]
if(isset($_GET['name']))
{
$name = $_GET['name'];
$query = "SELECT type, size, content FROM uploadfiles WHERE name = '$name'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
echo $content;
exit;
}
[/PHP]
In your query, you're selecting the type, size and content. However in the list function, you're adding the name variable. So, the name var will store the type, the type will store the size, the size var will store the content and the content will be empty (I think). You don't need to redeclare the name, you got it in the URL. Try
[PHP]
list($type, $size, $content) = mysql_fetch_array($result);
[/PHP]
instead of
[PHP]
list($name, $type, $size, $content) = mysql_fetch_array($result);
[/PHP]
I hope that this helps you
| | Member | | Join Date: Mar 2007
Posts: 77
| | | re: files wont open Quote:
Originally Posted by tonymanuel [PHP]
if(isset($_GET['name']))
{
$name = $_GET['name'];
$query = "SELECT type, size, content FROM uploadfiles WHERE name = '$name'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
echo $content;
exit;
}
[/PHP]
In your query, you're selecting the type, size and content. However in the list function, you're adding the name variable. So, the name var will store the type, the type will store the size, the size var will store the content and the content will be empty (I think). You don't need to redeclare the name, you got it in the URL. Try
[PHP]
list($type, $size, $content) = mysql_fetch_array($result);
[/PHP]
instead of
[PHP]
list($name, $type, $size, $content) = mysql_fetch_array($result);
[/PHP]
I hope that this helps you
i have got it to open the files thanx...but 1 problem, the files are all shown in a single line instead of a column...
| | Newbie | | Join Date: Jul 2008
Posts: 4
| | | re: files wont open Quote:
Originally Posted by Mubs i have got it to open the files thanx...but 1 problem, the files are all shown in a single line instead of a column... add a breakline '<br />' after each link.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,949
| | | re: files wont open Quote:
Originally Posted by tonymanuel [PHP]
if(isset($_GET['name']))
{
$name = $_GET['name'];
$query = "SELECT type, size, content FROM uploadfiles WHERE name = '$name'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
echo $content;
exit;
}
[/PHP]
In your query, you're selecting the type, size and content. However in the list function, you're adding the name variable. So, the name var will store the type, the type will store the size, the size var will store the content and the content will be empty (I think). You don't need to redeclare the name, you got it in the URL. Try
[PHP]
list($type, $size, $content) = mysql_fetch_array($result);
[/PHP]
instead of
[PHP]
list($name, $type, $size, $content) = mysql_fetch_array($result);
[/PHP]
I hope that this helps you Applause needed - that was a great catch.
OP: In your or die() statements, you should put something useful there. i.e. mysql_error() this holds the error the query generated.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,501 network members.
|