Re: file_exists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Nov 14, 2007 5:04 PM, Chris <dmagick@xxxxxxxxx> wrote:

> Ronald Wiplinger wrote:
> > Chris wrote:
> >> Ronald Wiplinger wrote:
> >>> I am having troubles with the function  file_exists()
> >>>
> >>> I tried the full path like:
> >>>
> >>> if (file_exists('/srv/www/....../images/pic412.jpg') {
> >>>     echo "<IMG SRC='images/pic412.jpg'>";
> >>> } else {
> >>>     echo "&nbsp;"                   //    picture is missing!
> >>> }
> >>>
> >>> No matter if I use the full path or just images/pic412.jpg, it always
> >>> shows the picture is missing!
> >
> > Sorry, I expressed it wrong.
> >
> > The picture is displayed if it exists!
> > However, when the picture does not exist, then the missing file is not
> > recognized (hence the subject line "file_exists")
>
> Are you 100% sure you are looking for the file in the right place then?



I've run into similar problems where I *thought* I was looking in the
correct location... but I wasn't. Take this for example....

<?php // index.php?page=hello/hi
$page = $_GET['page'];
if (file_exists ("$page.php")) {
    include ("$page.php");
}
?>

Notice that 'hello/hi.php' is being included from within index.php. So,
references to images in 'hello/hi.php' will be the same as if called
directly from index.php (if the images are in /images/ and index.php is in
/):

<?php
// Correct: in /index.php AND in /hello/hi.php
$anImage = 'images/anImage.jpg';
// or
$anImage = '/images/anImage.jpg';

// Incorrect: /hello/hi.php
$anImage = 'images/anImage.jpg';
// By doing it this way, you're assuming the
// image is in /hello/images and not /images
?>

Ok, hope I didn't confuse things! Just something to consider.

~Philip

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux