Show images/pictures from SQL database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Memphis
Forum Newbie
Posts: 1
Joined: Sat Jul 17, 2004 10:57 pm
Location: Memphis, TN

Show images/pictures from SQL database

Post by Memphis »

Hi!
I have a query that gets and outputs pictures from an SQL database.
Here is the code

Code: Select all

<?PHP
  $fname = $_POST["fname"];
  $lname = $_POST["lname"];
  
  $connectionstring = odbc_connect("photos","","");

  $query = "SELECT firstname, lastname, image FROM ImageDB WHERE(firstname=$fname AND lastname=$lname)";

  $queryexec = odbc_exec($connectiontsring, $query);
  $result = odbc_fetch_array($queryexec);

  echo $result['firstname'] . "<BR>" . $result['lastname'] . "<BR>";

  $filename = "photo.jpg";
  $fp = fopen ($filename, "w");
  echo "<img src="$filename"><BR>";
  fclose($fp);
  unlink ($filename);
?>
"Image" is binary datatype.
My problem is this: Since the size of all variables in PHP is 4kb, I can only see that much of the photo. The rest just does not show up.
Is there any way that I can get around this problem?

Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I haven't ever had a problem with very large variables.. I routinely have 130K binary image strings floating in my scripts..

your script opens and truncates $filename, closes it, then deletes it.. all without letting the browser actually read the file..
Post Reply