473,320 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

files wont open

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]
Jul 1 '08 #1
4 1452
[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
Jul 1 '08 #2
Mubs
77
[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...
Jul 1 '08 #3
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.
Jul 1 '08 #4
Markus
6,050 Expert 4TB
[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.
Jul 1 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jerry | last post by:
I'm having just a bit of trouble wrapping my brain around the task of working with folders that are above the site's root folder. I let users upload photos (.jpg/.gif files) which can...
23
by: **Developer** | last post by:
Is there an easy way to copies all files in a directory into another directory? What about coping subdirectories too? Thanks in advance for any info
1
by: lion | last post by:
helo...... i need help for how to read/write file in C++ i use fstream but i wont to open file one time for all functions(file is glopal) and i wont the file be open in the constructor of my...
1
by: skinymike | last post by:
when i allow user to download a media file such as midi or wav files. It automatically open the files using Windows Media Player. Its fine works ok. But when i allow user to download a theme files...
5
by: Robert Hicks | last post by:
Is it good practice to do something like: try: f1 = file('file1') f2 = file('file2') except: # catch the exception Or do you do a try/except for each open?
9
by: Justin Rich | last post by:
looking for the best approach to reading a real time log file. The file gets updated pretty quickly, always appended to the end. do i really need to just keep re-opening the file and reading the...
1
by: agarwalsunitadhn | last post by:
hello I had completed my project and i want to upload my files to hostserver. i uploaded it through FTP but when i open the files by online. then i got a list of files that is Index of...
0
by: alivip | last post by:
Is python provide search in parent folder contain sub folders and files for example folder name is cars and sub file is Toyota,Honda and BMW and Toyota contain file name camry and file name corola,...
2
by: hharry | last post by:
Hello All, Does anyone know of a method to automatically detect if a file is corrupted ? Due to a failed backup process a number of files were corrupted. The files are mostly .xls, .doc, .pdf....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.