+ Reply to Thread
Results 1 to 1 of 1

Thread: Pure ASP Upload script with additional features

  1. #1
    Ask Me About Dragons :D Shadow Wizard has a spectacular aura about Shadow Wizard has a spectacular aura about Shadow Wizard's Avatar
    Join Date
    Jul 2008
    Location
    Israel
    Posts
    795
    Blog Entries
    2
    Real Name
    Yahav
    Rep Power
    5

    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
    1. fixed file name problem - thanks Shem for pointing on this problem.
    2. fixed problem causing you could not use Response.Redirect
      after you saved the uploaded files - thanks Shemzilla!
    3. changed the code so that passing new file name without
      extension will use the original extension.
    4. 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.

    Related threads:
    Errors:
    getting Permission Denied error
    script hangs on SaveToDisk call
    Bad file name or number error
    getting Operation Not Allowed error
    Server.CreateObject Access Error when creating Scripting.Dictionary
    Invalid procedure call or argument: 'MidB' error when uploading
    Browser just hangs, file is not uploaded

    Additional Features:
    uploading whole directory
    resize the uploaded images on the fly
    inserting uploaded images names to database
    email the uploaded file
    Get files by their corresponding form element name

    General Help:
    where the uploaded files will be saved?
    uploading any file (not only images)
    uploading large files
    preventing user from uploading non image files
    help implementing the code
    change the name of the uploaded file change it completely
    display uploaded image after uploading it
    integrating the upload with existing code
    using GetFileIndexByName with non IE browsers
    Attached Files

+ Reply to Thread

Similar Threads

  1. Problem with Vb script
    By Learner in forum ASP Development
    Replies: 4
    Last Post: September 17th, 2009, 10:51 AM
  2. File Upload and then Print?
    By Centurion in forum .NET Development
    Replies: 11
    Last Post: July 22nd, 2009, 12:05 PM
  3. Need a script made.
    By jpaytoncfd in forum PHP Development
    Replies: 2
    Last Post: June 12th, 2009, 08:00 PM
  4. altering a script
    By Shem in forum JavaScript Programming
    Replies: 2
    Last Post: May 18th, 2009, 10:23 AM
  5. add additional footer to gridview
    By peebman2000 in forum .NET Development
    Replies: 13
    Last Post: May 2nd, 2008, 02:50 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO