Forum Moderators: coopster

Message Too Old, No Replies

Problem with locating image directory from root

         

milkman_joe

5:13 am on Sep 21, 2005 (gmt 0)

10+ Year Member



All i want to do is change my following method that works fine, so that it checks from the root directory.
This is what i originally have and works fine:

$file_name = 'products/'.$pId.'s.jpg';
if (file_exists($file_name))
$test = true;
else
$file_name = 'template/noimage.gif';

I tried changing the following line but it does not locate the image:
$file_name = '../products/'.$pId.'s.jpg';

The folder 'products' and 'template' are in the root directory.
ie. root/products

Could anyone help me with this problem?
Thanks in advance.

R e b r a n d t

6:35 am on Sep 21, 2005 (gmt 0)



$file_name = '/products/'.$pId.'s.jpg';

milkman_joe

2:21 pm on Sep 21, 2005 (gmt 0)

10+ Year Member



I replaced the top line with:
$file_name = '/products/'.$pId.'s.jpg';

however it did not fix the problem.
Now it shows every image as 'template/noimage.gif'.

Even if the file exists in the products table, it is not finding it for some reason.

dcrombie

3:13 pm on Sep 21, 2005 (gmt 0)



$file_name = "{$_SERVER['DOCUMENT_ROOT']}/products/{$pId}s.jpg";

;)

milkman_joe

2:03 am on Sep 22, 2005 (gmt 0)

10+ Year Member



Ok i replaced the first line with:
$file_name = "{$_SERVER['DOCUMENT_ROOT']}/products/{$pId}s.jpg";

However a weird problem remains. It is recognising which files exists, and which files do not exist. (correct)

So the files that do not exist, it displays noimage.gif. (correct)

However, the files it did recognise that existed, are being displayed as broken links.

jatar_k

2:47 am on Sep 22, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



to test the file you need to use the server root path as you did but to display the image you need the web root path. So...

$file_name = '/products/'.$pId.'s.jpg';
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $file_name))
$test = true;
else
$file_name = 'template/noimage.gif';

milkman_joe

6:58 am on Sep 23, 2005 (gmt 0)

10+ Year Member



Thanks

Its working now.