Marcus Maximus
03-01-2007, 07:53 PM
I trying to download a BLOB from my web page i have successfully uploaded files to the database but when i'm downloading im encountering problems
showfiles.php that list al the files in the DB table (this works properly)
<?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><font size="2" face="Verdana" color="#FFFFFF">
Description</font></b></td>
<td width="33%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">
Type</font></b></td>
<td width="33%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">
File</font></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">
<font face="Verdana" size="1">
<?php echo $row["blobTitle"]; ?>
</font>
</td>
<td width="33%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10">
<font face="Verdana" size="1">
<?php echo $row["blobType"]; ?>
</font>
</td>
<td width="33%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10"><font face="Verdana" size="1">
<a href="downloadfile.php?fileId=<?php echo $row["blobId"]; ?>">
Download now
</a></font>
</td>
</tr>
<?php
}
echo "</table>";
?>
downloadfile.php causes me problems it outputs the error Invalid blobId specified
<?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.";
}
?>
showfiles.php that list al the files in the DB table (this works properly)
<?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><font size="2" face="Verdana" color="#FFFFFF">
Description</font></b></td>
<td width="33%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">
Type</font></b></td>
<td width="33%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">
File</font></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">
<font face="Verdana" size="1">
<?php echo $row["blobTitle"]; ?>
</font>
</td>
<td width="33%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10">
<font face="Verdana" size="1">
<?php echo $row["blobType"]; ?>
</font>
</td>
<td width="33%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10"><font face="Verdana" size="1">
<a href="downloadfile.php?fileId=<?php echo $row["blobId"]; ?>">
Download now
</a></font>
</td>
</tr>
<?php
}
echo "</table>";
?>
downloadfile.php causes me problems it outputs the error Invalid blobId specified
<?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.";
}
?>