note 57934 added to function.file-exists

From: Date: Wed, 19 Oct 2005 14:37:48 +0000
Subject: note 57934 added to function.file-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-97232@lists.php.net to get a copy of this message
The following script checks if there is a file with the same name and adds _n to the end of the file name, where n increases. if img.jpg is on the server, it tries with img_0.jpg, checks if it is on the server and tries with img_1.jpg. <?php $img = "images/".$_FILES['bilde']['name']; $t=0; while(file_exists($img)){ $img = "images/".$_FILES['bilde']['name']; $img=substr($img,0,strpos($img,"."))."_$t".strstr($img,"."); $t++; } move_uploaded_file($_FILES['bilde']['tmp_name'], $img); ?> ---- Manual Page -- http://www.php.net/manual/en/function.file-exists.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57934 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57934&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57934&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57934&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57934&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57934&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57934&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57934&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57934&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97232) next »