Jump to content

[SOLVED] Need help with file download script please


pedmeister

Recommended Posts

I've set up a file upload and download site with the files being saved to a server and the info to a mysql db. The problem I have is that when people click on the download link created they don't get a valid file from the server.

 

Here's the download code where I'm sure the error is  :'(

<?php
include 'library/config.php';
include 'library/opendb.php';

$query  = "SELECT id, name FROM upload2 ORDER BY name";
$result = mysql_query($query) or die('Error, query failed');

	$columns = 4;
	if(mysql_num_rows($result) == 0)
	{
		echo "Database is empty <br>";
	}
	else
	{
		echo "<table align=\"center\" border=\"1\" cellpadding=\"6\" cellspacing=\"0\" class=\"blacknormalbold\"><tr>";
		$iloop = 0;
		$break_flag = false;
		while(list($id, $name) = mysql_fetch_array($result))
		{
			$break_flag = ($iloop++ % ($columns));
			if( 0 == $break_flag ){
				echo "</tr><tr>";

			}
			echo "<td>";
			echo "<a href=download.php?id=$id>$name</a><br></td>";
		}
		$remain = $columns - $break_flag ;
		if( 0 < $remain){
					echo "<td colspan=\"$remain\"> </td>";
		}

		echo "</tr></table>";
	}



include 'library/closedb.php';
?>

 

Any help greatly appreciated

 

Peds

You may have to show the source of download.php.

 

Otherwise I think that may be a bug and what you want is:

 

 

echo '<a href="$name">$name</a><br></td>';

 

Please take care, I have changed your quotes.

 

monk.e.boy

 

The code is from download.php

 

Below is download.php in it's entirety

 

<?php
error_reporting(E_ALL);
if(isset($_GET['id']))
{
include 'library/config.php';
include 'library/opendb.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);

include 'library/closedb.php';	
exit;
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Links 2003 LTS File Repository</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="Upload Links 2003 LTS files" />
<meta name="keywords" content="links 2003, LTS files, pga tour, golf, offline tours, online tours"/>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {color: #FF0000}
.style2 {
color: #FFFFFF;
font-weight: bold;
font-style: italic;
}
.style3 {
font-size: 14px;
font-weight: bold;
}
-->
</style>
</head>

<body>
<table width="778" border="0" align="center" cellpadding="1" cellspacing="1">
  <tr>
    <td bgcolor="#333333"><table width="777" height="355" border="0" align="center" cellpadding="0" cellspacing="0">
      <!-- Header Starts Here -->
      <tr bgcolor="#FFFFFF">
        <td height="90" valign="top"><?php include("includes/header.php");?></td>

      </tr>
      <!-- Header Ends Here -->
  <!-- Center Body Starts Here -->
      <tr>

        <td height="150" valign="top" bgcolor="#FFFFFF"><table width="99%"  border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="1%" valign="top"><img src="images/security_box_left_panel.jpg" width="9" height="8" /></td>
            <td width="98%" valign="top" background="images/security_center_box_horizontal.jpg"><img src="images/security_center_box_horizontal.jpg" width="9" height="8" /></td>
            <td width="1%" valign="top" background="images/security_center_box_horizontal.jpg"><img src="images/security_box_right_panel.jpg" width="9" height="8" /></td>
          </tr>
          <tr>
            <td height="200" valign="top" background="images/security_box_left_vertical.jpg"><img src="images/security_box_left_vertical.jpg" width="9" height="8" /></td>
            <td valign="top"><table width="99%"  border="0" align="center" cellpadding="0" cellspacing="0">
                <tr valign="top">
                  <td width="17%" height="200" bgcolor="#FFFFFF"><a href="http://1and1.co.uk/xml/init/?k_id=9660732" target="_blank"><img src="http://banner.1and1.co.uk/xml/banner?size=5&number=1" width="120" height="600"  border="0"/></a></td>
                  <td width="83%"><table width="99%" height="257"  border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
                      <td width="45%" height="19" valign="middle" bgcolor="#333333"><div align="center" class="style2">
                        <div align="right">Welcome to the </div>
                      </div></td>
                      <td width="55%" valign="middle" bgcolor="#333333"><div align="right" class="style2">
                        <div align="left">  Links 2003 LTS files Repository</div>
                      </div></td>
                    </tr>
                    <tr>
                      <td height="34" colspan="2" valign="top"><table width="100%" height="101"  border="0" cellpadding="1" cellspacing="1" class="blacknormalbold">
                        <td width="98%" align="center" valign="top" class="blacknormalbold">
					<br />
					  <p align="center" class="blacknormalbold">Download Links 2003 LTS files below
					<?php
include 'library/config.php';
include 'library/opendb.php';

$query  = "SELECT id, name FROM upload2 ORDER BY name";
$result = mysql_query($query) or die('Error, query failed');

	$columns = 4;
	if(mysql_num_rows($result) == 0)
	{
		echo "Database is empty <br>";
	}
	else
	{
		echo "<table align=\"center\" border=\"1\" cellpadding=\"6\" cellspacing=\"0\" class=\"blacknormalbold\"><tr>";
		$iloop = 0;
		$break_flag = false;
		while(list($id, $name) = mysql_fetch_array($result))
		{
			$break_flag = ($iloop++ % ($columns));
			if( 0 == $break_flag ){
				echo "</tr><tr>";

			}
			echo "<td>";
			echo "<a href=download.php?id=$id>$name</a><br></td>";
		}
		$remain = $columns - $break_flag ;
		if( 0 < $remain){
					echo "<td colspan=\"$remain\"> </td>";
		}

		echo "</tr></table>";
	}



include 'library/closedb.php';
?>
</td>

                       <tr>
                          <td height="7" colspan="4" align="center" valign="top"><img src="images/security_menu_separator.jpg" width="100%" height="5" /></td>
                          </tr> 
                          </table></td>
                    </tr>
                    <tr>
                      <td height="68" colspan="2" valign="top"><table width="100%" height="92"  border="0" cellpadding="1" cellspacing="1" class="greynormal">
                        <tr>
                          <td width="23%" rowspan="2" align="center" valign="middle"><a href="http://www.winzip.com" target="_parent"><img src="images/winzip.jpg" alt="Winzip" width="120" height="120" border="0" /></a></td>
                          <td height="68" colspan="3" valign="top"><div align="center" class="subheading">
                            <p align="left" class="style1">ALL FILES ON THE SITE ARE IN .ZIP FORMAT!! </p>
                            <p align="left" class="greynormal">Please upload files in .zip format. If you don't have a program for this already, we recommend using WINZIP. Click on the icon (left) to go to the program's site. </p>
						<div align="left" class="greynormal"></div>
                          </div></td>
                        </tr>
                        <tr>
                          <td width="67%" height="10" valign="top"> </td>
                          <td width="2%" align="center" valign="middle"></td>
                          <td width="8%" align="left" valign="middle"></td>
                        </tr>
                        <tr>
                          <td height="7" colspan="4" align="center" valign="top"><img src="images/security_menu_separator.jpg" width="100%" height="5" /></td>
                        </tr>
                      </table></td>
                    </tr>
                    <tr valign="middle" bgcolor="#FFFFFF">
                      <td height="5" colspan="2" class="googleheading"><!-- Google Advertisement --></td>
                    </tr>
                    <tr > <!-- bgcolor="#384ECA" -->
                      <td height="34" colspan="2" valign="top"><table width="90%"  border="0" align="center" cellpadding="5" cellspacing="10">
                        <tr align="center" valign="top">
                          <td height="50" bgcolor="#FFFFFF" class="blacknormal" >
					  <div style="border:thin solid black; width:350px; height:80px">
<form method="get" target="_blank" ACTION=" http://order.1and1.co.uk/xml/order/domaincheck">
<p class="blacknormalbold">Trust 1&1 Internet for your domain name registration, from only £1.99/year!. Check now!</p>
<table border="0" width="320">
<tr>
<td class="form">
<input name="__currentindex[domaincheck]" value="0" type="hidden"/>
<input name="__sendingdata" value="1" type="hidden"/>
<input name="__pageflow" value="Order" type="hidden"/>
<input name="k_id" value="9660732" type="hidden"/>
<input size="20" maxlength="500" name="multicheck.Domain" type="text"/>
</td>
<td>
<select style="width:60px" name="multicheck.Tlds">
<option value="co.uk">co.uk</option>
<option value="me.uk">me.uk</option>
<option value="org.uk">org.uk</option>
<option value="info">info</option>
<option value="com">com</option>
<option value="mobi">mobi</option>
<option value="net">net</option>
<option value="org">org</option>
<option value="eu">eu</option>
<option value="info">info</option>
<option value="name">name</option>
<option value="biz">biz</option>
<option value="us">us</option>
</select>
</td>
<td> 

</td>
<td>
<input type="submit" name="Submit" value="Check Now"/>
</td>
</tr>
</table>
</form>
</div>
					  <br>
<a href="http://www.apcd-courses.com" target="_blank"><img src="images/apcdcourses.gif" alt="apcd-courses" width="300" height="66" vspace="5" border="0" ></a>

					  </td>
                        </tr>
                      </table></td>
                    </tr>
                  </table></td>
                </tr>
              </table>
             </td>
            <td valign="top" background="images/security_center_right_virtical.jpg"><img src="images/security_center_right_virtical.jpg" width="9" height="8" /></td>
          </tr>
          <tr>
            <td height="8" valign="top"><img src="images/security_center_box_left_bottom.jpg" width="9" height="8" /></td>
            <td valign="top" background="images/security_center_box_horizontal_bottom.jpg"><img src="images/security_center_box_horizontal_bottom.jpg" width="9" height="8" /></td>
            <td valign="top"><img src="images/security_center_box_right_bottom.jpg" width="9" height="8" /></td>
          </tr>
        </table></td>



      </tr>
   <!-- Center Body Starts Here -->
      <!-- Footer Starts Here -->
      <tr bgcolor="#FFFFFF">
        <td height="21" valign="top"><?php include("includes/footer.php");?></td>
      </tr>
      <!-- Footer Ends Here -->
    </table></td>
  </tr>
</table>
</body>
</html>

 

Hope that helps as I'm not sure what you mean  :'(

 

Peds

That should work.

 

Try commenting out the 'header' commands and see what the browser sends you.

 

Then add the headers back in and use Live HTTP Headers to see what the server is sending you.

 

I expect your database is not returning the correct file path. So when you stream your file it is not there and is producing an error.

 

monk.e.boy

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.