Click to See Complete Forum and Search --> : Limiting what kind of files users can upload...
goofy1989
11-05-2005, 02:17 PM
I'm using ASPUpload (http://www.aspupload.com) to allow users to upload images. The problem is that they can upload any file they want, not just images. I was wondering if there was a way to force them to upload ONLY .JPGs. Is this possible, thanks!
Giskard
11-05-2005, 09:16 PM
It's been a while since I've used ASPUpload (I now do all uploads in ASP.NET), but I believe there is a "NAME" property to the Files object (the one that you use to say "file xxxxxx.xxx was uploaded") that you could check prior to the actual save, If the file is not a .jpg then return an error message, otherwise save the file. I think the code would look something like:
Set Upload = Server.CreateObject("Persits.Upload.1")
if ucase(Right(Upload.Files.Name, 3)) = "JPG" then
Upload.Save "c:\upload"
else
Response.write "You can only upload JPG files"
end if
You could also check the Upload.Files.Size property if you wanted to limit the file size that they are uploading
buntine
11-06-2005, 05:42 AM
The object contains a files collection, so you would have to explicity refer to the object via a name or index.
If UCase(Right(Upload.Files(0).Name, 3)) = "JPG" Then
...
With ASPUpload, you can use the SetMaxSize function to limit allowed file sizes.
Regards.