Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Rename uploaded images/files
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Rename uploaded images/files

 Post Reply Post Reply
Author
klr3 View Drop Down
Groupie
Groupie
Avatar

Joined: 20 February 2003
Status: Offline
Points: 103
Post Options Post Options   Thanks (0) Thanks(0)   Quote klr3 Quote  Post ReplyReply Direct Link To This Post Topic: Rename uploaded images/files
    Posted: 23 June 2010 at 9:37pm
Hi!
 
I would like to rename uploaded files to a unique filename (based on date/time), but can´t seem to figure out how to.
 
I use following components: Persits AspUpload 3 and AspJpeg (AspJpeg i just for image resize..)
 
I have looked in to "/functions/functions_upload.asp", but with no luck Cry
 
The filename should be something like this:
 

Dim ImageDate
Dim MyNewFileName
ImageDate = Year(Now()) & "" & Month(Now()) & "" & Day(Now()) & "" & Hour(Now()) & "" & Minute(Now())& "" & Second(Now())
MyNewFileName = "websitename_"& ImageDate
 
Could anyone guide me or help with some code?
Thanks!
Back to Top
klr3 View Drop Down
Groupie
Groupie
Avatar

Joined: 20 February 2003
Status: Offline
Points: 103
Post Options Post Options   Thanks (0) Thanks(0)   Quote klr3 Quote  Post ReplyReply Direct Link To This Post Posted: 25 June 2010 at 1:43pm
Found at solution my self, but it´s limited to images alone:
 

'Filter file name to remove anything that isn't allowed by the filters
 
strNewFileName = formatFileName(strNewFileName)
 
'If this is an iamge
If strUploadType = "image" Then
 
'Declare new variables
 
'Imagename based on date/time
Dim ImageDate
Dim MyNewFileName
 
'Get extension (only .gif, .jpg, .png)
Dim MyNewFileExt
ImageDate = Year(Now()) & "" & Month(Now()) & "" & Day(Now()) & "" & Hour(Now()) & "" & Minute(Now())& "" & Second(Now())
MyNewFileName = "my_prefix_here"& ImageDate
MyNewFileExt = Mid(strNewFileName, InStrRev(strNewFileName, "."), 4)
 
strNewFileName = MyNewFileName & MyNewFileExt
End if
 
Imagenames ends up with a name like this example:
"my_prefix_here_2010625144219.jpg"
 
If you have any comments, please let me know Wink


Edited by klr3 - 25 June 2010 at 2:17pm
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.