Re: [PHP] Creating dynamic names for images

2002-12-05 Thread Marek Kilimajer
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/$namebr;
   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


 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Creating dynamic names for images

2002-12-04 Thread Jason Wong
On Thursday 05 December 2002 00:48, 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.

uniqid()

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
I just remembered something about a TOAD!
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Creating dynamic names for images

2002-12-04 Thread Joakim Andersson
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
 


Insert your file-info into the database
Use mysql_insert_id() (or similar) to get the ID of your new row. (You 
do have an auto_increment column, right?)
Use that ID as filename.

Regards
Joakim Andersson


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Creating dynamic names for images

2002-12-04 Thread Justin French
well,

a) use a table in the DB with the primary key (id) as an auto-increment
column. 1, 2, 3 etc.  Use this ID as the name of the file 1.jpg, 2.gif, and
perhaps store the filetype / extension as well, so that you know what
filename to look for in the folder.

b) something as simple as file_exists() may be enough... if a file with that
name already exists, you could append something to it, like a random number,
and try again.

Ypu certainly don't have to ask the user to rename the file... YOU should be
in charge of naming it.


Justin


on 05/12/02 3:48 AM, Davíð Örn Jóhannsson ([EMAIL PROTECTED]) 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
 
 

Justin French

http://Indent.com.au
Web Development  
Graphic Design



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php