displaying images stored as path in mysql

From: Date: Wed, 09 Aug 2000 03:48:45 +0000
Subject: displaying images stored as path in mysql
Groups: php.general 
Request: Send a blank email to php-general+get-10839@lists.php.net to get a copy of this message
Someone please help me. I've been struggling with this for days. I've stored images (.jpg) as a name in a database. (Not as a BLOB but rather as part of a path to a directory on my disk). I want to now retrieve them. All I'm getting is a broken image or I'll get binary garbage on the browser. I have no clue how to solve this problem. Please go easy on me I'm a newbie to php4. Here is the script I've written to "try" to display the image: <HTML> <HEAD> <TITLE>Show Image</TITLE></HEAD> <BODY> <?php if($submit){ $path = "/home/janine/scanned"; require('sig.inc'); $link =mysql_connect($host,$user,$password); if(!mysql_select_db($db)) print "Couldn't open $db: ".mysql_error(); $query = "SELECT picture FROM Image WHERE '$picture' = picture"; $result=mysql_query($query,$link); $data = mysql_result($result,0,"picture"); print $data; //Header("Content-type: image/jpeg"); //readfile("$path/$data"); print "<Img Src=\"$path/$data\">"; Mysql_Close($link); //Close the thread } ?> <FORM ENCTYPE="multipart/form-data" METHOD="POST" ACTION="<?php echo $PHP_SELF?>"> Image to get: <input type="text" name="picture" size="25"> <input type="submit" name="submit" value="Get it!"> </FORM> </BODY> </HTML> If you notice I've commented out the Header() line because I get a warning if it's there. And I've been going back and forth between the <IMG SRC> tag and the readfile() function. If I use the readfile function I get binary garbage. If I use the <IMG SRC> tag I get a broken image. I think the problem has something to do with the header() function. But I don't know where to put it? Please please help....I'm very frustrated. Thanks in advance -- Janine Roe mjroe@bellatlantic.net

« previous php.general (#10839) next »