Allow Upload based on Image Orientation
Want to allow only Landscape or only Portrait Images?
Question:
How can I only allow Landscape or Portrait images being uploaded using Pure ASP Upload?
Answer:
To prevent a design from being wrecked by user-images being uploaded with Pure ASP Upload, it is possible to force only Landscape or Portrait images to be uploaded and if wanted, to be resized.Some handcoding is needed to get the desired result.
The regular code for Pure ASP Upload 3 looks somewhat like this, depending on the settings made:
<%
'*** Pure ASP File Upload 3.0.15
' Process form form1
Dim pau, DMX_uploadAction, UploadRequest, UploadQueryString, pau_thePath, pau_nameConflict, pau_saveWidth, pau_saveHeight
Set pau = new PureUpload
pau.ScriptLibrary = "ScriptLibrary"
pau.ConflictHandling = "uniq"
pau.StoreType = "file"
pau.UploadFolder = """images"""
pau.AllowedExtensions = "GIF,JPG,JPEG,BMP,PNG" ' "images"
pau.ProcessUpload
pau.SaveAll
if pau.Done then Response.Redirect "succes.asp"
%>
To make sure only landscape images are uploaded, edit the code like this. Make sure the correct Name for the Upload field is used. In this example the name foto is used!
<%
'*** Pure ASP File Upload 3.0.15
' Process form form1
Dim pau, DMX_uploadAction, UploadRequest, UploadQueryString, pau_thePath, pau_nameConflict, pau_saveWidth, pau_saveHeight
Set pau = new PureUpload
pau.ScriptLibrary = "../ScriptLibrary"
pau.ConflictHandling = "uniq"
pau.StoreType = "file"
pau.UploadFolder = """../images"""
pau.AllowedExtensions = "GIF,JPG,JPEG,BMP,PNG" ' "images"
pau.ProcessUpload
If UploadFormRequest("MM_insert") <> "" Then
If pau.Fields("foto").Width > pau.Fields("foto").Height Then
pau.SaveAll
if pau.Done then Response.Redirect "succes.asp"
Else
Response.Redirect "error.asp"
End If
End If
%>
These changes will first check if the form is submitted, to prevent errors from happening on load of the page. Then the check for Landscape images is performed. If the image is landscape, the upload will continue. If not, the upload will abort and the user is redirected to an error page.
If Resizing is also enabled on the page, the edited code looks somewhat different:
<%
'*** Pure ASP File Upload 3.0.15
' Process form form1
Dim pau, DMX_uploadAction, UploadRequest, UploadQueryString, pau_thePath, pau_nameConflict, pau_saveWidth, pau_saveHeight
Set pau = new PureUpload
pau.ScriptLibrary = "../ScriptLibrary"
pau.ConflictHandling = "uniq"
pau.StoreType = "file"
pau.UploadFolder = """../images"""
pau.AllowedExtensions = "GIF,JPG,JPEG,BMP,PNG" ' "images"
pau.ProcessUpload
If UploadFormRequest("MM_insert") <> "" Then
If pau.Fields("foto").Width > pau.Fields("foto").Height Then
pau.SaveAll
if pau.Done then Response.Redirect "succes.asp"
%>
<%
' Smart Image Processor 2.5.4
Dim sip1
Set sip1 = New ImageProcessor
sip1.Key = "FF1BBD9A-18B7-4460-BC08-E3064AD2384D"
sip1.ScriptFolder = "../ScriptLibrary"
sip1.Component = "Auto"
sip1.Source = "upload"
sip1.AutoOrient = false
sip1.KeepMetaData = false
sip1.Matte = "#FFFFFF"
sip1.UploadFields = ""
sip1.GetFiles
While sip1.HasFiles
sip1.LoadFromSource
sip1.Resize 133, 100, true
sip1.Overwrite = true
sip1.SaveJPEG 100
sip1.MoveNext
Wend
Set sip1 = Nothing
%>
<%
Else
Response.Redirect "error.asp"
End If
End If
%>
Comments
Be the first to write a comment
You must me logged in to write a comment.