AN_SafeFileName

Clean filename from special characters to make it safe for server upload
Then if parameter passed, it will cut the filename to certain length
Characters will be removed are \/*+=?&$#%,
NewLength if more than 0, it will cut to get the left part of filename for this length
NewLength make it as 0 or "" to get full filename


Public

Tested

My Own Work
Function AN_SafeFileName(FileName, NewLength)
 ' Rename file to make safe to upload to server
 ' Replacing special char in file name \/*+=?&$#%,
 ' Then if passed NewLength, will cut it to 1st NewLength haraters
 Rett      = FileName
 Rett      = Replace(Rett, "/", "")
 Rett      = Replace(Rett, "\", "")
 Rett      = Replace(Rett, "*", "")
 Rett      = Replace(Rett, "+", "")
 Rett      = Replace(Rett, "=", "")
 Rett      = Replace(Rett, "?", "")
 Rett      = Replace(Rett, "&", "")
 Rett      = Replace(Rett, "$", "")
 Rett      = Replace(Rett, "#", "")
 Rett      = Replace(Rett, "%", "")
 Rett      = Replace(Rett, ",", "")
 If IsNumeric(NewLength) Then
  If Clng(NewLength) > 0 Then
   Rett    = Left(Rett, NewLength)
  End If
 End If
 AN_SafeFileName  = Rett
End Function

FileName, NewLength

Views 360 Downloads 77

Classic ASP File System
ANmarAmdeen
695
Attachments
Revisions

v1.0