maw
01-22-2004, 10:20 AM
Hi, I am trying to allow users to upload only some types of images under a certain size
I can get the basic upload working fine using
<%
Set Upload = Server.CreateObject("Persits.Upload.1")
Upload.SetMaxSize 5000, True
Count = upload.savevirtual("/test/upload")
%> </font id="green">
I found this guide for restricting the file size and type digitalcolony.com/01/upload/ (http://digitalcolony.com/01/upload/)
so I am using the shared code -
<%
intMaxFileSize = 8000
strUploadFolder = "c:\uploadFolder"
Function isFileSizeOK(bytes)
'=== restrict file byte size
byteMAX = intMaxFileSize
If bytes > byteMAX Then
isFileSizeOK = FALSE
Else
isFileSizeOK = TRUE
End If
End Function
Function isValidFile(filename)
'=== define what file types you will permit to upload
fileExtension = lcase(right(filename,4))
select case fileExtension
case ".gif",".jpg",".png","jpeg"
isValidFile = TRUE
case else
isValidFile = FALSE
end select
End Function</font id="green">
with the aspupload code
<%
Sub uploadPersists
Set up = Server.CreateObject("Persits.Upload.1")
up.OverwriteFiles = TRUE
up.SetMaxSize intMaxFileSize
up.Save uploadFolder
For Each File in up.Files
fileName = File.ExtractFileName
If isValidFile(fileName) Then
If isFileSizeOK(File.OriginalSize) Then
strUploadStatus2 = "File [" & filename & "] Uploaded Successfully! "
Else
strUploadStatus2 = "ERROR: File Too Large: " & fileName & " (" & File.OriginalSize & " bytes)"
File.Delete
End If
Else
File.Delete
strUploadStatus2 = "ERROR: This File Type is restricted from uploading: " & fileName
End If
Next
End Sub
%> </font id="green">
If I use it as it is (obviously adding my folder) I get the SaveVirtual error. When I change it to virtual I get the following error - Server.MapPath() error 'ASP 0171 : 80004005'
I have tried removing strUploadFolder and just using
up.Savevirtual ("/test/upload") </font id="green">
Basically this doesnt throw up any errors - it just doesnt do anything. I have played around with the code a bit and can get it to upload but it simply disregards the file type or size restrictions - no errors it just doesnt seem to be processing it.
Anyone have any ideas why I cant get this working - I imagine I am missing something totally obvious. Or does have anyone managed to so a similar thing - and if so can I steal your knowledge?
Thanks
I can get the basic upload working fine using
<%
Set Upload = Server.CreateObject("Persits.Upload.1")
Upload.SetMaxSize 5000, True
Count = upload.savevirtual("/test/upload")
%> </font id="green">
I found this guide for restricting the file size and type digitalcolony.com/01/upload/ (http://digitalcolony.com/01/upload/)
so I am using the shared code -
<%
intMaxFileSize = 8000
strUploadFolder = "c:\uploadFolder"
Function isFileSizeOK(bytes)
'=== restrict file byte size
byteMAX = intMaxFileSize
If bytes > byteMAX Then
isFileSizeOK = FALSE
Else
isFileSizeOK = TRUE
End If
End Function
Function isValidFile(filename)
'=== define what file types you will permit to upload
fileExtension = lcase(right(filename,4))
select case fileExtension
case ".gif",".jpg",".png","jpeg"
isValidFile = TRUE
case else
isValidFile = FALSE
end select
End Function</font id="green">
with the aspupload code
<%
Sub uploadPersists
Set up = Server.CreateObject("Persits.Upload.1")
up.OverwriteFiles = TRUE
up.SetMaxSize intMaxFileSize
up.Save uploadFolder
For Each File in up.Files
fileName = File.ExtractFileName
If isValidFile(fileName) Then
If isFileSizeOK(File.OriginalSize) Then
strUploadStatus2 = "File [" & filename & "] Uploaded Successfully! "
Else
strUploadStatus2 = "ERROR: File Too Large: " & fileName & " (" & File.OriginalSize & " bytes)"
File.Delete
End If
Else
File.Delete
strUploadStatus2 = "ERROR: This File Type is restricted from uploading: " & fileName
End If
Next
End Sub
%> </font id="green">
If I use it as it is (obviously adding my folder) I get the SaveVirtual error. When I change it to virtual I get the following error - Server.MapPath() error 'ASP 0171 : 80004005'
I have tried removing strUploadFolder and just using
up.Savevirtual ("/test/upload") </font id="green">
Basically this doesnt throw up any errors - it just doesnt do anything. I have played around with the code a bit and can get it to upload but it simply disregards the file type or size restrictions - no errors it just doesnt seem to be processing it.
Anyone have any ideas why I cant get this working - I imagine I am missing something totally obvious. Or does have anyone managed to so a similar thing - and if so can I steal your knowledge?
Thanks