views:

46

answers:

2

Hi,

I am working on a PHP script that automatically displays an image based on certain elements (which don't matter for the sake of the question since that part works perfectly fine.) Out of the browsers I have tested it in, the images are correctly displayed on Google Chrome, Internet Explorer, and Safari. However, they do not appear on Firefox or Opera. In Firefox, nothing is displayed and in Opera the path of the image is http://server/folder/%5Cimages%5C40.jpg which should be http://server/folder/images/40.jpg. The code used to generate the URL is as follows:

 echo "<div class='jumih3'>" . $row['fname'] . " " . $row['lname'] . "</div>";
 $image = JURI::root() . "\/images\/" . $row['id'] . ".jpg";
 $imagetest = JPATH_ROOT . "\/images\/" . $row['id'] . ".jpg";
 if (file_exists($imagetest))
 {
 echo "<br /><img src='" . $image . "'width='100' height='100' /><br />";
 }

This is part of a Joomla site and the JURI:root() and JPATH_ROOT provide absolute locations of the server. The way that Opera parses the URL I'm suspecting something is wrong with the way I am escaping the slashes. However, when I tried using / instead of \/ the images did not appear in any browser.

EDIT: As you can see from Zannjaminderson's answer, the problem's fixed in a facepalm kind of way.

A: 

Call me a noob if you like, but I notice you're testing file_exists($imagetest) and then using $image as the source for your image...shouldn't you be using the one you tested for/testing for the one you're using?

Zannjaminderson
Greg is testing the local file system to see if the file exists, and then passing the public URI.
Will Bickford
From my understanding, JURI:ROOT() provides the root URI and JPATH_ROOT provides the root address for applications so that's why I set it up that way.
Greg Zwaagstra
Will explained my thought process better, though. ;)
Greg Zwaagstra
I'm going to go with your answer being correct since you got me thinking about the structure and when I tried using / I had put it on the wrong line. So thanks for indirectly calling out my idiocy.
Greg Zwaagstra
I'm happy to help even in a strange and indirect way - thanks also for the clarification, Will. And for not calling me an n00b.
Zannjaminderson
A: 

you don't need to escape slashes. when you use / what kind of address does it produce for each image? what platform?

Mohammad
It was producing http://server/folder/%5Cimages%5C40.jpg and by using / I managed to fix the issue.
Greg Zwaagstra