note 81408 modified in function.file-exists by felipe

From: Date: Sun, 23 Mar 2008 11:21:05 +0000
Subject: note 81408 modified in function.file-exists by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137358@lists.php.net to get a copy of this message
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... --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 (#137358) next »