Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.";
}

?>
Reply With Quote
  #2 (permalink)  
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

Reply With Quote
  #3 (permalink)  
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

Reply With Quote
  #4 (permalink)  
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

Reply With Quote
  #5 (permalink)  
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

Reply With Quote
  #6 (permalink)  
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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:56 PM.


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