Discuss Pure ASP Upload script with additional features in the Code Bank forum on ASP Free. Pure ASP Upload script with additional features Code Bank forum containing sample code and scripts to help solve common problems. Take a look and use the code to assist in your projects.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.
Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.
Posts: 31,109
Time spent in forums: 3 Months 3 Weeks 2 Days 20 h 18 m 8 sec
Reputation Power: 2919
Pure ASP Upload script with additional features
yet another upload script, however this time it let you control
some things that most script won't handle, for example it can
check images width and height.
upload script is attached in the zip file.
sample code using this upload script:
Code:
<!-- #include file="ShadowUploader.asp" -->
<%
Dim objUpload
If Request("action")="1" Then
Set objUpload=New ShadowUpload
If objUpload.GetError<>"" Then
Response.Write("sorry, could not upload: "&objUpload.GetError)
Else
Response.Write("found "&objUpload.FileCount&" files...<br />")
For x=0 To objUpload.FileCount-1
Response.Write("file name: "&objUpload.File(x).FileName&"<br />")
Response.Write("file type: "&objUpload.File(x).ContentType&"<br />")
Response.Write("file size: "&objUpload.File(x).Size&"<br />")
Response.Write("image width: "&objUpload.File(x).ImageWidth&"<br />")
Response.Write("image height: "&objUpload.File(x).ImageHeight&"<br />")
If (objUpload.File(x).ImageWidth>200) Or (objUpload.File(x).ImageHeight>200) Then
Response.Write("image to big, not saving!")
Else
Call objUpload.File(x).SaveToDisk(Server.MapPath("Uploads"), "")
Response.Write("file saved successfully!")
End If
Response.Write("<hr />")
Next
Response.Write("thank you, "&objUpload("name"))
End If
End If
%>
<form action="<%=Request.ServerVariables( "Script_Name" )%>?action=1" enctype="multipart/form-data" method="POST">
File1: <input type="file" name="file1" /><br />
File2: <input type="file" name="file2" /><br />
File3: <input type="file" name="file3" /><br />
Name: <input type="text" name="name" /><br />
<button type="submit">Upload</button>
</form>
as you can see, in the Uploader code you can control the
maximum upload size (total of all files plus form data) and
various messages.
the upload take place once you initialize the upload object.
however, the files will not be saved to disk until
SaveToDisk method is called!
you can check file type by ContentType or FileName, and you
can check if the file is valid image by checking the ImageWidth
or ImageHeight: if they're -1 it's not valid image.
revision history
fixed file name problem - thanks Shem for pointing on this problem.
fixed problem causing you could not use Response.Redirect
after you saved the uploaded files - thanks Shemzilla!
changed the code so that passing new file name without
extension will use the original extension.
changed the code so that it would append extension of
original file to the given fie name, if this given file name does
not have any extension.
Posts: 31,109
Time spent in forums: 3 Months 3 Weeks 2 Days 20 h 18 m 8 sec
Reputation Power: 2919
as I said, you can check if the file is valid image by checking ImageWidth - if
it's -1 the file is not valid image, regardless of its extension. for example:
Posts: 668
Time spent in forums: 6 Days 7 h 4 m 19 sec
Reputation Power: 28
is there any way of changing the image width ,height or quality while saving it to disk.
__________________
Mark
If you found a post particularly helpful, show your appreciation by clicking the "scales" icon in the bar just above the post, at the right hand side.
Posts: 31,109
Time spent in forums: 3 Months 3 Weeks 2 Days 20 h 18 m 8 sec
Reputation Power: 2919
Quote:
Originally Posted by MARKEDAGAIN
is there any way of changing the image width ,height or quality while saving it to disk.
nope, classic ASP has its limits, that's one of them...
you'll have to install and use some 3rd party component for this, or better yet - switch
to ASP.NET where it's possible using simple code.
Posts: 31,109
Time spent in forums: 3 Months 3 Weeks 2 Days 20 h 18 m 8 sec
Reputation Power: 2919
Quote:
Originally Posted by jefwic
Thanks, the script blocking did the trick. Strange, NAV is supposed to prompt for action when it blocks scripts. As well, all my other ASP code was working fine..just not the savetodisk.
Thanks!
Regards,
Jeff Wickenheiser
no problem, you're not alone in this.. it's one of the most common problems I've seen.
NAV prompts only when it find virus, Script Blocking is done silently behind the scenes.
Posts: 31,109
Time spent in forums: 3 Months 3 Weeks 2 Days 20 h 18 m 8 sec
Reputation Power: 2919
the second parameter in the SaveToDisk method is the file name to use when
saving the file - if left blank, the original file name will be used.
or are you asking how to append the date to the file name?
Posts: 31,109
Time spent in forums: 3 Months 3 Weeks 2 Days 20 h 18 m 8 sec
Reputation Power: 2919
I have cleaned up this thread and Splitted each group of posts into its
own thread. the links can be found in the first post in this thread under
"Related threads".
Please start new thread, pointing on this one, if you got any specific problem
with the ShadowUploader.
For general questions or problems, post here and worst case I'll move it when
the time come.