Web Wiz
Home
Home
Hosting Services
Hosting Services
Knowledgebase
Knowledgebase
Community and Support Forums
Support Forums
Customer Login
Customer Login

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

Web Wiz Web Hosting 30 Day Free Trial

Windows Hosting 30 Day Free Trial, with no obligation, on all our Windows Web and Reseller Hosting Packages.

For more information see our Windows Hosting 30 Day Free Trial page.

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
  Share Topic   

Forum Jump Forum Permissions View Drop Down



Become a Fan on Facebook Follow us on Twitter Web Wiz on Google+ Community Forums Web Wiz Blogs Web Wiz News
Company Information | Contact Web Wiz | Terms & Conditions | Privacy Policy

Prices exclude VAT unless otherwise stated - $, € prices shown as a guideline only
Web Wiz Ltd, Unit 10E Dawkins Road Ind. Est, Poole, Dorset, UK, BH15 4JD
Copyright ©2001-2012 Web Wiz - All rights reserved