note 81408 modified in function.file-exists by danbrown

From: Date: Sun, 11 Jan 2009 18:38:27 +0000
Subject: note 81408 modified in function.file-exists by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149066@lists.php.net to get a copy of this message
When using file_exists, seems you cannot do: <?php foreach ($possibles as $poss) { if ( file_exists(SITE_RANGE_IMAGE_PATH .$this->range_id .'/ '.$poss .'.jpg') ) { // exists } else { // not found } } ?> so you must do: <?php foreach ($possibles as $poss) { $img = SITE_RANGE_IMAGE_PATH .$this->range_id .'/ '.$poss .'.jpg' if ( file_exists($img) ) { // exists } else { // not found } } ?> Then things will work fine. This is at least the case on this Windows system running php 5.2.5 and apache 2.2.3 Not sure if it is down to the concatenation or the fact theres a constant in there, i'm about to run away and test just that... --was-- When using file_exists, seems you cannot do: foreach ($possibles as $poss) { if ( file_exists(SITE_RANGE_IMAGE_PATH .$this->range_id .'/ '.$poss .'.jpg') ) { // exists } else { // not found } } so you must do: foreach ($possibles as $poss) { $img = SITE_RANGE_IMAGE_PATH .$this->range_id .'/ '.$poss .'.jpg' if ( file_exists($img) ) { // exists } else { // not found } } Then things will work fine. This is at least the case on this Windows system running php 5.2.5 and apache 2.2.3 Not sure if it is down to the concatenation or the fact theres a constant in there, i'm about to run away and test just that... http://php.net/manual/en/function.file-exists.php

« previous php.notes (#149066) next »