Page 1 of 9 123 ... Last
  • Jump to page:
    #1
  1. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2921

    Post 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

    Comments on this post

    • baseballdude_ agrees : Badabababa I'm loooovin it.
    • lewy agrees : Very nice script. Great job Shadow :)
    • Levurax agrees : Good one
    • JustXtreme agrees : I searched and Searched and nothing, But Shadow Saves the Day. Great Work!!!
    • kanenas.net agrees : Great work !
    • Khrysller agrees : this rulez
    • shem agrees : btw... thanks for the script:D
    • Dr_Rock agrees : Been a while since I dropped in, I remember you wrote this script, certainly came in handy, thanks!
    • ajayp40 agrees : ITS BEAUTIFUL,CHEERS USED IT MANY TIME NOW
    • WolverineHD agrees : This is excellent!
    Attached Files
    Last edited by Shadow Wizard; April 6th, 2009 at 09:23 AM.
  2. #2
  3. Expert Learner
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Feb 2005
    Location
    Wisconsin
    Posts
    1,909
    Rep Power
    97
    Wow dude! this rocks! I have an idea how, but I didn't wanna mess anything up...how do I only allow images?

    Also, I found that to make the file if you're manually naming it to have the valid extension regardless, the If statement can look like this:
    Code:
    		If Len(strNewFileName) = 0 Then
    			strPath = strPath & m_fileName
    		Else  
    			strPath = strPath & strNewFileName & Right(m_fileName, InStrRev(m_fileName, "."))
    		End If
    Seriously though dude, great work!
  4. #3
  5. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2921
    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:
    ASP Code:
    		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 />")
    			If objUpload.File(x).ImageWidth<0 Then
    				Response.Write("invalid image!")
    			Else  
    				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("Uploa  ds"), "")
    					Response.Write("file saved successfully!")
    				End If
    			End If
    			Response.Write("<hr />")
    		Next
    		Response.Write("thank you, "&objUpload("name"))

    this will not save non-image files. as for extension, I fear I didn't understand what you
    mean - you try to save the file with different extension??
  6. #4
  7. Expert Learner
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Feb 2005
    Location
    Wisconsin
    Posts
    1,909
    Rep Power
    97
    I'm sorry I missed the check image part shadow, i was so excited to see the code
    this will not save non-image files. as for extension, I fear I didn't understand what you
    mean - you try to save the file with different extension??
    I was talking about if you want to save the file with a different name - the code I gave makes sure the correct extension is attached.
  8. #5
  9. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2921
    Originally Posted by baseballdude_
    I'm sorry I missed the check image part shadow, i was so excited to see the code

    I was talking about if you want to save the file with a different name - the code I gave makes sure the correct extension is attached.
    yep, that's true... this way only file name can be passed without extension. well done!
  10. #6
  11. Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    Montreal
    Posts
    668
    Rep Power
    30
    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.
  12. #7
  13. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2921
    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.
  14. #8
  15. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2921
    update: fixed bug with multiply file upload which crashed.
    credit for this goes to Olórin - thanks!

    Comments on this post

    • grdnwesl agrees : The Weasel bows his furry little head to the all powerful Shadow
  16. #9
  17. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2921
    Important update:
    improved efficiency of the upload script. files up to 10 MB should be
    uploaded very fast.
  18. #10
  19. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2921
    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.
  20. #11
  21. No Profile Picture
    Contributing User
    ASP Mastermind (5000+ posts)

    Join Date
    Aug 2005
    Location
    North East, UK
    Posts
    6,191
    Rep Power
    136
    Where is the best part in the script to change the filename.

    e.g.
    original image name = myimage.jpg

    before saving to disk append the date (would require to split the filename at the period, append the date, then rejoin the parts)
    myimage_01062006.jpg

    or prefix the image name with objUpload("name") from the form
    username_myimage.jpg
  22. #12
  23. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2921
    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?
  24. #13
  25. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2921
    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.
  26. #14
  27. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Nov 2006
    Posts
    3
    Rep Power
    0

    Nothing to upload error message


    Hey Shadow Wizard

    Great looking script, having a bit of trouble using it though.

    Im getting an error that says "nothing to upload" well i know the file is there, so any ideas?

    Cheers
  28. #15
  29. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2921
    hey Paul glad to see you chose my uploader.. this
    error means you didn't send any files or you didn't
    set multipart/form-data for the form.

    post your full HTML and we'll see...
Page 1 of 9 123 ... Last
  • Jump to page:

Similar Threads

  1. Upload Script with HTTPget
    By comix2000 in forum ASP Development
    Replies: 1
    Last Post: January 20th, 2005, 06:50 PM
  2. Hot Or Not Script Upload Error
    By marya in forum ASP Development
    Replies: 5
    Last Post: October 14th, 2004, 08:12 PM
  3. Huge / Pure upload?
    By fatmanman in forum ASP Development
    Replies: 0
    Last Post: September 14th, 2004, 06:20 AM
  4. Replies: 2
    Last Post: August 27th, 2004, 03:58 PM
  5. Upload script
    By kutty in forum ASP Development
    Replies: 0
    Last Post: October 1st, 2003, 03:36 PM

IMN logo majestic logo threadwatch logo seochat tools logo