Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 1st, 2007, 06:39 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Uploading and downloading MySQL BLOB's

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.";
}

?>
 
Old March 3rd, 2007, 09:41 AM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

problem solved

 
Old August 8th, 2007, 05:06 AM
Registered User
 
Join Date: Aug 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to meisam
Default

dude, hi, i want to do the same thing uploading and downloading the files into mysql by blob type and through JSP, would you help me in both up and downloading area ?

i do need some help

 
Old August 22nd, 2007, 01:39 AM
Registered User
 
Join Date: Aug 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi! hello

 
Old February 1st, 2008, 06:53 AM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

http://www.onlamp.com/pub/a/php/2000...php_mysql.html

very nice example

 
Old March 10th, 2008, 11:32 PM
Friend of Wrox
 
Join Date: Jul 2003
Location: South San Francisco, CA, USA.
Posts: 128
Thanks: 0
Thanked 1 Time in 1 Post
Default

Marcus,
Your problem is on your while(row = mysql_fetch_array($result)):
This is a Numeric Array (result s/b like $row[0]) in contrast to your Associative Array $row['blogId'].....
how this helps
John





Similar Threads
Thread Thread Starter Forum Replies Last Post
Resume Uploading And Downloading sumith ASP.NET 1.0 and 1.1 Professional 0 May 24th, 2007 01:40 AM
code for downloading & uploading file in server mhadz JSP Basics 1 January 23rd, 2007 02:27 AM
uploading and downloading cyber_kaley Classic ASP Databases 1 January 31st, 2005 11:14 PM
MySql downloading Lee Fenner MySQL 1 October 8th, 2004 03:42 AM
Up/downloading Files VB+MySQL mike123abc Pro VB 6 3 May 24th, 2004 03:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.