note 60458 added to function.file-exists

From: Date: Sat, 07 Jan 2006 21:08:15 +0000
Subject: note 60458 added to function.file-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-101367@lists.php.net to get a copy of this message
I wrote this little handy function to check if an image exists in a directory, and if so, return a filename which doesnt exists e.g. if you try 'flower.jpg' and it exists, then it tries 'flower[1].jpg' and if that one exists it tries 'flower[2].jpg' and so on. It works fine at my place. Ofcourse you can use it also for other filetypes than images. <?php function imageExists($image,$dir) { $i=1; $probeer=$image; while(file_exists($dir.$probeer)) { $punt=strrpos($image,"."); if(substr($image,($punt-3),1)!==("[") && substr($image,($punt-1),1)!==("]")) { $probeer=substr($image,0,$punt)."[".$i."]". substr($image,($punt),strlen($image)-$punt); } else { $probeer=substr($image,0,($punt-3))."[".$i."]". substr($image,($punt),strlen($image)-$punt); } $i++; } return $probeer; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.file-exists.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60458 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60458&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60458&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60458&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60458&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60458&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60458&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60458&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60458&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101367) next »