PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 307,168 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,565 people online right now. Registration is fast and FREE... Join Now!




download files problem with header

 

download files problem with header, i need someone can help me to look my codes and tell me the errors

shahrul

18 Mar, 2009 - 11:10 PM
Post #1

New D.I.C Head
*

Joined: 11 Feb, 2009
Posts: 12


My Contributions
CODE

/*
i have source code that need download from uploaded files but i have problem with header.
can someone can tell me what the errors. ty
*/

<?php
require_once "header.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
<style type="text/css">
<!--
body,td,th {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 10px;
}
-->
</style></head>

<body>
<form name="form1" method="post" action="<?php echo $PHP_SELF; ?>">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <div id="Layer1" style="position:absolute; width:199px; height:115px; z-index:1; left: 11px;">
    <table width="200" border="1" cellspacing="0" cellpadding="1">
      <tr>
        <td><a href="ViewFilesUploaded.php">View Uploaded files </a></td>
      </tr>
      <tr>
        <td><a href="ViewUploadField.php">Upload files </a></td>
      </tr>
      <tr>
        <td><a href="viewDeleteFiles.php">Delete files </a></td>
      </tr>
    </table>
  </div>
  <p>&nbsp;</p>
  <div id="Layer2" style="position:absolute; width:758px; height:115px; z-index:2; left: 216px; top: 311px;">
    <table width="722" border="1" cellspacing="0" cellpadding="1">
      <tr bgcolor="#FFFF99">
        <td width="380">File Name </td>
        <td width="63">Size(byte)</td>
        <td width="98">Type</td>
        <td width="88">Date Uploaded </td>
        <td width="71">Action</td>
      </tr>
      <?php
        $hostname = "localhost";
        $db_user = "root";
        $db_password = "1234";
        $database = "myinternshipdb";
        $db_table = "upload";
    
        $db = mysql_connect($hostname, $db_user, $db_password);
        mysql_select_db($database,$db);

$query = "SELECT id, name, size, type, dateUpload FROM upload";
$result = mysql_query($query) or die('Error, query failed');
while($myrow = mysql_fetch_array($result))
{

?>
      <tr bgcolor="#33FFCC">
      
        <td><?php echo $myrow['name']; ?></td>
        <td><?php echo $myrow['size']; ?></td>
        <td><?php echo $myrow['type']; ?></td>
        <td><?php echo $myrow['dateUpload']; ?></td>
        <td><a href="<?php echo "viewFilesUploaded.php?id=".$myrow['id']; ?>">[Download]</a></td>
      </tr>
      <?
      }
      ?>
    </table>
  </div>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>
    <?php
if(isset($_GET['id']))
{
// if id is set then get the file with the id from database

        $hostname = "localhost";
        $db_user = "root";
        $db_password = "1234";
        $database = "myinternshipdb";
        $db_table = "upload";
    
        $db = mysql_connect($hostname, $db_user, $db_password);
        mysql_select_db($database,$db);


$id    = $_GET['id'];
$query = "SELECT name, type, size, dateUpload, content " .
         "FROM upload WHERE id = '$id'";

$result = mysql_query($query) or die('Error, query failed');
while($myrow= mysql_fetch_array($result));
{
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;
}
mysql_close();
exit;
}

?>
  </p>
</form>


</body>
</html>


User is offlineProfile CardPM
+Quote Post


Posts in this topic

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 06:36PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month