I'm able to echo the image pathname using the while loop. I can't seem to show the actual image. When I try to echo using the image tag it shows nothing.

$imagepath = $_SERVER['DOCUMENT_ROOT'].'/images/';
if ($result) {
	while ($row = mysql_fetch_array($result)) {
		echo $row['title'];
		$img = $imagepath.$row['image'];
		echo "<image src=\"". $imagepath.$row['image'] ."\">";
	}
}
    echo "<img src='".$img."'>";
    

      Opps I made a mistake on the img tag. Anyways I've tried that and several other ways and still just getting blanks. I've also tried escaping php and using html img tag then going back to php. Everything I do seems to get blanks. I know the images are in the directory and the image path in the database is correct.
      I've also tried:

      echo '<img src=/"'.$imagepath.$row['image'].'/">';
      echo '<img src="' . $imagepath.$row['image'] . '" />';
      

        Update on this:
        When I click view source on the php page the <img src="C:/wamp/www/images/image.jpg" /> is there.

        Firefox doesn't show anything, but right click view source shows the tag there. When I type the whole C:/wamp/www/images/image.jpg to the url box in firefox it says firefox doesn't know how to open the file because the protocal isn't associated with any programs.

        On IE when I type the filepath on the url box it shows the image no problem. When I use IE to view the php page I get empty boxes without the picture. When I save the source file as a html file, everything shows fine in IE but still not firefox.

        Any inputs? This is tested using wampserver2 and on windows vista.

          You need to use the url path to the file, you can't display a file using the file system path. You need the path of the file relative to the document root of your webserver.

            rsmith wrote:

            You need to use the url path to the file, you can't display a file using the file system path. You need the path of the file relative to the document root of your webserver.

            So...I can't do this using wampserver? I need to be on a live server?
            $_SERVER['DOCUMENT_ROOT'] = C:/wamp/www/

            How can I work with this if I can't use that path?

              You shouldn't be doing that anyway. I'm not familiar with WAMP but I use Xampp and when you install it, you can go to http://localhost/path/to/file.php and access your files where "localhost" references your local workstation. So let's say I have an image called test.jpg in an images subfolder in the document root. By default, in Xampp the document root is physically located at:

              C:\Program Files\xampp\htdocs

              This means that the File System path is : C:\Program Files\xampp\htdocs\images\test.jpg

              The URL of the file would be: http://localhost/images/test.jpg

              Get it?

                Thanks for the help. I just ended up using a constant as the path so I can call it from my included pages.

                  Write a Reply...