Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hey guys its been a while

 

As I have said I will share this code on downloading files here (btw this is not complete but this is just a backbone idea of what it is, so expect some flaws on this)

 

dataB.php

<?php
// if result returns false.....
	    if ($result == 0) {
		    echo "Dude, Where's my Files? <br>"; //...output this
	    } else { //...output this if result returns at least 1 entry
		    echo "<table border='1'>
			    <tr>
				    <td>FileEntry</td>
				    <td>Filename</td>
				    <td>Type</td>
				    <td>Size(bytes)</td>
				    <td>Time received</td>
			    </tr>";
//iterate through the rows of the existing query
		    for ($i = 0; $i < $rows; $i++) {
			    $data = mysql_fetch_object($result);
			    echo "<tr>";
			    echo "<td>" . $data->FileEntry. "</td>";
			    echo "<td>" . $data->Filename . "</td>";
			    echo "<td>" . $data->Filetype . "</td>";
			    echo "<td>" . $data->Filesize . "</td>";
			    echo "<td>" . $data->Received . "</td>";
			    echo "<td><a href='dataB.php?id=$data->id'>Collect here</a></td>";
			    echo "</tr>";
		    } echo "</table>";
	    }
	    mysql_free_result($result); // releases memory
	    mysql_close(); // closes database connection
	    ?>

 

dataA.php

<?php
$id = $_GET['id'];
if ($id) {
   mysql_connect("myhost", "myroot", "") or die(mysql_error());
   mysql_select_db("FileCollections") or die(mysql_error());

//generate queries
   $query = "SELECT Contents, Filetype, Filename, Filesize FROM FileData WHERE id=$id";

   $result = mysql_query($query);
   $data = mysql_result($result, 0, "Contents");
   $name = mysql_result($result, 0, "Filename");
   $size = mysql_result($result, 0, "Filesize");
   $type = mysql_result($result, 0, "Filetype");

// return output
   header("Content-type: $type");
   header("Content-length: $size");
   header("Content-Disposition: attachment; filename=$name");
   echo $data;
}
?>

 

BTW Larry, If this has already been posted on the forum, then I apologize as I have tried to find an existing post of this otherwise I hope this will help any one in future.

 

Thx

Link to comment
Share on other sites

 Share

×
×
  • Create New...