Re: displaying images stored as path in mysql

From: Date: Wed, 09 Aug 2000 04:18:24 +0000
Subject: Re: displaying images stored as path in mysql
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-10840@lists.php.net to get a copy of this message
On 8 Aug, Janine Roe wrote: > 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 print "<Img Src=\"$path/$data\">"; should work OK IF $path is under your server root - otherwise you'll get the broken image icon because your web server can't get at the image. If $path is not under your server root, you will need to call another script with a suitable header as the image source and (other bits I can't recall). My suggestion for the least amount of frustration and the simplest way of doing what you want would be to move the images directory under your server root. Or at least symlink it. Cheers -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#10840) next »