[PHP] Re: Image Upload, renaming question

2001-11-16 Thread George Whiffen

Joe,

One approach that works for me is to have a separate IMAGE table with an automatically 
generated
primary key image_id (auto_increment with MySQL).  I don't use this store the image, 
but just to
give me the unique name for the image file.  I also use the IMAGE table to store away 
the original
image name, and the image type and dimensions from GetImageSize.  Type and dimensions 
can be useful
to have stored in case you need to set IMG WIDTH and HEIGHT dynamically to maintain 
proportions if
the image is over-sized for the page it's on and/or manipulate and image with gd 
functions.

The IMAGE table is shared across the whole site to guarantee unique image names and 
any updates of
images are always handled as inserts to stop problems with  browsers caching old 
images.  image_id
is then held on the table where the use of the image is recorded e.g. the table 
holding a page's
content.  The actual directory where the images reside is not actually held in the 
database but set
as a global in a standard include.  This makes it easier to move between 
machines/sites etc. without
changing data. 

This seems to work well, you can use standard code for image upload/update/deletion 
and functions
for image_insert,
image_delete etc.

Cheers,

George

Joe Van Meer wrote:
 
 Thx Richard, I would like the files to all be dumped into one directory,
 each with a unique name. Then I will create a path and store that in the db.
 Thx for the ideas, I will check them out and get back to youvia this thread.
 
 Cheers Joe:)
 
 Richard Lynch [EMAIL PROTECTED] wrote in message
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  Joe Van Meer wrote:
 
   Hi there, I have an upload form on my website that works great, however
 I
   have come to a roadblock...how the heck do I rename the copied file?
   Everytime I upload an image it overwrites the old one with the new. The
   code below uploads the file and displays the following:
  
   Your photo has been uploaded successfully.
   Size of Image in Bytes: 36315
   Image Type: image/pjpeg
   File exists on server.
   /rotatingimages/C:\PHP\uploadtemp\php12D.tmp   -- I notice that this is
 a
   temporary name
 
  If two files were being uploaded at once, you'd get two different names...
 
  But it's entirely up to *YOU* to decide where to copy the file to.  Maybe
  you'd *WANT* to replace files as they were uploaded.
 
  I tend to use the user's filename and preg_replace() to get rid of
  everything except a-zA-Z._-  and then checking where I'm copying to tack
 on
  1, 2, 3, ... until I find a new filename that's not in use.
 
  You should also start using http://php.net/move_uploaded_file instead of
  copy or whatever you are doing.
 
  --
  Like music?  http://l-i-e.com/artists.htm
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: Image Upload, renaming question

2001-11-15 Thread Joe Van Meer

Thx Richard, I would like the files to all be dumped into one directory,
each with a unique name. Then I will create a path and store that in the db.
Thx for the ideas, I will check them out and get back to youvia this thread.

Cheers Joe:)


Richard Lynch [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Joe Van Meer wrote:

  Hi there, I have an upload form on my website that works great, however
I
  have come to a roadblock...how the heck do I rename the copied file?
  Everytime I upload an image it overwrites the old one with the new. The
  code below uploads the file and displays the following:
 
  Your photo has been uploaded successfully.
  Size of Image in Bytes: 36315
  Image Type: image/pjpeg
  File exists on server.
  /rotatingimages/C:\PHP\uploadtemp\php12D.tmp   -- I notice that this is
a
  temporary name

 If two files were being uploaded at once, you'd get two different names...

 But it's entirely up to *YOU* to decide where to copy the file to.  Maybe
 you'd *WANT* to replace files as they were uploaded.

 I tend to use the user's filename and preg_replace() to get rid of
 everything except a-zA-Z._-  and then checking where I'm copying to tack
on
 1, 2, 3, ... until I find a new filename that's not in use.

 You should also start using http://php.net/move_uploaded_file instead of
 copy or whatever you are doing.

 --
 Like music?  http://l-i-e.com/artists.htm




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]