4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 Viewing images stored in mysql as blob data?
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
badger
Junior WebHelper
Junior WebHelper


Joined: 08 Oct 2004
Posts: 10

PostPosted: Thu Dec 30, 2004 4:58 pm (19 years, 12 months ago) Reply with QuoteBack to Top

Hi peeps,

Im having an issue getting viewing images I have added to a mysql database. I have a dump of the database below.

Code:
CREATE TABLE binary_data_files (
   file_id tinyint(3) unsigned NOT NULL auto_increment,
   bin_data mediumblob NOT NULL,
   description tinytext NOT NULL,
   filename varchar(50) NOT NULL,
   filesize varchar(50) NOT NULL,
   filetype varchar(50) NOT NULL,
   PRIMARY KEY (file_id)
);


I can successfully add blob images to the database but when trying to call them for usage just simply doesn't work.

The script I am trying to use is below.

Code:
<?php

global $id;



if(!is_numeric($id))

die("Invalid file_id specified");

$dbServer = "localhost";

$dbDatabase = "phone";

$dbUser = "root";

$dbPass = "";



$sConn = mysql_connect($dbServer, $dbUser, $dbPass)

or die("Couldn't connect to database server");



$dConn = mysql_select_db($dbDatabase, $sConn)

or die("Couldn't connect to database $dbDatabase");



$dbQuery = "SELECT bin_data, filetype";

$dbQuery .= "FROM binary_data_files";

$dbQuery .= "WHERE file_id = $id";

$result = mysql_query($dbQuery) or die("Couldn't get file list");



if(mysql_num_rows($result) == 1)

{

$filetype = @mysql_result($result, 0, "filetype");

$filecontent = @mysql_result($result, 0, "bin_data");



header("Content-type: $filetype");

echo $filecontent;

}

else

{

echo "Record doesn't exist.";

}

?>


Everytime I try to call an image (view.php?id=1) I get "Couldn't get file list"?

Can anyone help?

Thanks

Badger!
OfflineView User's ProfileFind all posts by badgerSend Personal Message
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Sat Jan 01, 2005 4:35 pm (19 years, 11 months ago) Reply with QuoteBack to Top

Add the following after the query and before the script is killed (with die() ):
Code:
print mysql_error();

That should let you know what's going wrong.

________________________________
It's turtles all the way down...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
badger
Junior WebHelper
Junior WebHelper


Joined: 08 Oct 2004
Posts: 10

PostPosted: Sun Jan 09, 2005 8:51 pm (19 years, 11 months ago) Reply with QuoteBack to Top

Thanks for this
OfflineView User's ProfileFind all posts by badgerSend Personal Message
zeeshan002
Junior WebHelper
Junior WebHelper


Joined: 21 Apr 2015
Posts: 1

PostPosted: Tue Apr 21, 2015 6:27 am (9 years, 8 months ago) Reply with QuoteBack to Top

Everytime I try to call an image (view.php?id=1) I get "Couldn't get file list"?

__________________
aliiii

________________________________
aliiii
OfflineView User's ProfileFind all posts by zeeshan002Send Personal Message
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.127724 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme