tags:

views:

34

answers:

2

Here is the 'id' and (path) 'name' in the MySql table called "upload":

 rec_id | name
--------+------------------------------------------------------
      1 | C:\Apache Tomcat 5.0.28\htdocs\ajax\images\blob1.jpg
      2 | C:\Apache Tomcat 5.0.28\htdocs\ajax\images\blob3.jpg
      3 | C:\Apache Tomcat 5.0.28\htdocs\ajax\images\blob2.jpg
+1  A: 

Get the image ID from $_GET[], set the Content-type with header(), then use readfile().

Ignacio Vazquez-Abrams
+1  A: 

You need to turn the image path into a web URL.

  1. Fetch the desired image path from the table

  2. Find out what your web root is (I'm guessing it's C:\Apache Tomcat 5.0.28\htdocs) and put it e.g. into a constant define("WEBROOT", "C:\...."); You could auto-detect the web root using DOCUMENT_ROOT but setting it manually is more reliable.

  3. Cut off the web root from the path str_replace(WEBROOT, "", $image_path);

  4. Voilá! You have a relative URL to your image that you can output: <img src='/ajax/images/blob1.jpg'>

Pekka
This assumes that all the pathnames in the database are somwhere under the document root.
Ignacio Vazquez-Abrams
@Ignacio Yes, I am assuming that is the case looking at the paths he shows. We'll see whether this is the case here. But my comment to your question was incorrect, I thought he was explicitly looking to *link* to the images, which he was not. Sorry.
Pekka
// I tried this in PHP:$string = '';$pic = '';if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_object($result)){ $string .= "<b>".$row->name."</b> - "; $string .= $row->phone." - </a>"; $string .= $row->picpath."</a>"; $pic .= "<img src='picpath'>"; $string .= "<br/>\n"; }}else{ $string = "No matches!";} echo $string;echo $pic;----------------and this gives me:Mark Hanson - 314-346-5856 - http://transeeq.com/kearney/images/bolts.jpg//--but the image did not come up
sonny5
You forgot the `$` in `picpath`.
Pekka
Here is the syntax that worked for me:if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_object($result)){ $string .= "<b>".$row->name."</b> - "; $string .= $row->phone." - </a>"; $string .= $row->title." - </a>"; $string .= $row->picpath."</a>"; //$pic .= "<img src='picpath' width='250' height='70' alt='some pic' />"; //$thumbImage = '<img src="'.$row->picpath.'" title="' . 'ddd' . '" />'; $thumbImage = '<img src="'.$row->picpath.'" title="' . '$row->title' . '" />'; $string .= "<br/>\n"; }}else{ $string = "No matches!";}
sonny5