im developing a website for users to upload and store files on a mysql database as a blob. i have the uploading form working but im having trouble with the downloading
I got an error and i can't see were its coming from
its the error in the downloadfile.php --->Invalid blobId specified
its gonna a make my head explode
showfiles.php script works fine and displays the list of files in the DB table
Code:
<?php
// Database connection variables
#connect to MySQL
$conn = @mysql_connect("***", "***","***")
or die("Could not Connect");
#select the specified database
$rs = @mysql_select_db("***", $conn)
or die("Could not select specified");
$dbQuery = "SELECT blobId, blobTitle, blobType ";
$dbQuery .= "FROM myBlobs ";
$dbQuery .= "ORDER BY blobTitle ASC";
$result = mysql_query($dbQuery) or die("Couldn't get file list");
?>
<a href="http://www.devarticles.com"><img border="0" src="http://www.devarticles.com/dlogo.gif"></a>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="100%">
<tr>
<td width="34%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b>
Description</b></td>
<td width="33%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b>
Type</b></td>
<td width="33%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b>
File</b></td>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td width="34%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10; margin-right: 10">
<?php echo $row["blobTitle"]; ?>
</td>
<td width="33%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10">
<?php echo $row["blobType"]; ?>
</td>
<td width="33%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10">
<a href="downloadfile.php?fileId=<?php echo $row["blobId"]; ?>">
Download now
</a>
</td>
</tr>
<?php
}
echo "</table>";
?>
THE PROBLEM IS IN HERE I THINK
downloadfile.php gives the error "Invalid blobId specified"
Code:
<?php
global $blobId;
if(!is_numeric($blobId))
die("Invalid blobId specified");
// Database connection variables
#connect to MySQL
$conn = @mysql_connect("****", "***","***")
or die("Could not Connect");
#select the specified database
$rs = @mysql_select_db("***", $conn)
or die("Could not select specified");
$dbQuery = "SELECT blobType, blobData ";
$dbQuery .= "FROM myBlobs ";
$dbQuery .= "WHERE blobId = $blobId";
$result = mysql_query($dbQuery) or die("Couldn't get file list");
if(mysql_num_rows($result) == 1)
{
$fileType = @mysql_result($result, 0, "blobType");
$fileContent = @mysql_result($result, 0, "blobData");
header("Content-type: $fileType");
echo $fileContent;
}
else
{
echo "Record doesn't exist.";
}
?>