hemmca
05-12-2005, 08:08 AM
I Am Sending A Mail With File Attachment.
But I Want Only .txt, .doc., .xls Files To Be Attached.
So How To Check File Extension And Give Alert Message On The Client Side Itself. Please Reply To This.
phpnovice
05-12-2005, 09:39 AM
You're talking about uploading a file that is, then, subsequently attached to a server-side mail? Such a file would have to be stored on your server, first, before it can be attached to a server-side mail. Thus, checking the file extension is pretty straightforward:
Dim ext, pos, str
ext = LCase(Request.Form("AttachFileName"))
pos = InStrRev(1, ext, ".", vbTextCompare)
If pos > 0 Then ext = Mid(ext, pos + 1)
If ext <> "doc" And ext <> "txt" And ext <> "xls" Then
Response.Write "<p>Invalid file extension.</p>" & vbCrLf
Response.End
End If
Bullschmidt
05-16-2005, 02:15 AM
And you might even want to only allow certain file types (or convert unknown file types to .txt or something) in your file uploading which of course would happen before the files were actually attached in an e-mail.