Re: Creating dynamic names for images

From: Date: Thu, 05 Dec 2002 11:34:53 +0000
Subject: Re: Creating dynamic names for images
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-127127@lists.php.net to get a copy of this message
I use this function: function sec_move_uploaded_file($tmp_name,$dir, $name) { if(file_exists($dir.'/'.$name)) {
       $ext=strrchr($name,'.');
       $basename=substr($name,0,strlen($name)-strlen($ext));
       $i=2;
       while(file_exists($dir.'/'.$basename.$i.$ext) ) {
           $i++;
       }
       $name=$basename.$i.$ext;
} //echo "copying $tmp_name to $dir/$name<br>"; return ( $r=move_uploaded_file($tmp_name, $dir.'/'.$name) ? $name : $r); } Davíð Örn Jóhannsson wrote:
I have a situation where I allow users to upload images, and I store the names of the images in a database and the images I store in a some folder on the server, but what I would like to do is to dynamically create names for the images and dont ever have to worry about if this name exists and with out having to got to the trouble of asking the user to change tha name of the file. So dose some one have a nice litle solution for this problem. Thanks, David


« previous php.general (#127127) next »