downloading files from a database via web page
Posted: Fri Oct 31, 2003 6:47 pm
Hi guys
I have manged to get a tutorial file working to some degree. I'm just stcuk on one bit of it. after uplaoding my file to my database, i then want to be able to download via webpage. My code doesnt seem to work. Can anyone see why?
This is the file main.php
This is the file download.php
at the momment when i click on the download link to downlaod the file. I just see a blank page.

I have manged to get a tutorial file working to some degree. I'm just stcuk on one bit of it. after uplaoding my file to my database, i then want to be able to download via webpage. My code doesnt seem to work. Can anyone see why?
This is the file main.php
Code: Select all
<?php
<?php
include "open_db.php";
$sql = "SELECT * FROM tbl_files ";
$sql .= "ORDER BY filename ASC";
$result = mysql_query($sql, $db); //result = mysql_query($sql, $db) or exit(mysql_error());
$rows = mysql_num_rows($result);
echo "<table>\n";
echo " <tr>\n";
echo " <td>Filename</td>\n";
echo " <td>Type</td>\n";
echo " <td>Size</td>\n";
echo " <td>Description</td>\n";
echo " <td> </td>\n";
echo " </tr>\n";
for ($i = 0; $i < $rows; $i++) {
$data = mysql_fetch_object($result);
//print_r($data);
// since our script is very small, i'm not going to escape out to html mode here
echo " <tr>\n";
echo " <td>$data->filename</td>\n";
echo " <td>$data->filetype</td>\n";
echo " <td>$data->filesize</td>\n";
echo " <td>" . stripslashes($data->description) . "</td>\n";
echo " <td>( <a href='download.php?id=".$data->id_Files."'>Download</a> )</td>\n";
echo " </tr>\n";
}
mysql_free_result($result);
mysql_close($db);
?>
?>Code: Select all
<?php
<?php
if (isset($_GET['id'])) {
include("open_db.php");
$sql = "SELECT bin_data, filetype, filename, filesize FROM tbl_files WHERE
id_files=$_GET['id']";
$result = mysql_query($sql, $db);
$data = mysql_fetch_object($result);
header("Content-type: $data->filetype");
header("Content-length: $data->filesize");
header("Content-Disposition: attachment; filename=$data->filename");
header("Content-Description: PHP Generated Data");
echo $data->bin_data;
}
?>
?>at the momment when i click on the download link to downlaod the file. I just see a blank page.