Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
 
Unread ASP Free Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old January 13th, 2006, 07:15 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,608 Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)  Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 12 h 53 m 47 sec
Reputation Power: 1400
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
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
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
Attached Files
File Type: zip ShadowUploader.zip (4.4 KB, 1732 views)

Last edited by Shadow Wizard : August 16th, 2007 at 04:13 AM.

Reply With Quote
  #2  
Old January 14th, 2006, 02:43 AM
baseballdude_'s Avatar
baseballdude_ baseballdude_ is offline
Expert Learner
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2005
Location: Wisconsin
Posts: 1,853 baseballdude_ User rank is Sergeant Major (2000 - 5000 Reputation Level)baseballdude_ User rank is Sergeant Major (2000 - 5000 Reputation Level)baseballdude_ User rank is Sergeant Major (2000 - 5000 Reputation Level)baseballdude_ User rank is Sergeant Major (2000 - 5000 Reputation Level)baseballdude_ User rank is Sergeant Major (2000 - 5000 Reputation Level)baseballdude_ User rank is Sergeant Major (2000 - 5000 Reputation Level)  Folding Points: 22104 Folding Title: Starter FolderFolding Points: 22104 Folding Title: Starter Folder
Time spent in forums: 1 Week 5 Days 9 h 18 m 15 sec
Reputation Power: 45
Send a message via AIM to baseballdude_ Send a message via MSN to baseballdude_ Send a message via Yahoo to baseballdude_ Send a message via Google Talk to baseballdude_
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!

Reply With Quote
  #3  
Old January 14th, 2006, 01:50 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,608 Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)  Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 12 h 53 m 47 sec
Reputation Power: 1400
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:
Original - ASP Code
  1.         Response.Write("found "&objUpload.FileCount&" files...<br />")
  2.         For x=0 To objUpload.FileCount-1
  3.             Response.Write("file name: "&objUpload.File(x).FileName&"<br />")
  4.             Response.Write("file type: "&objUpload.File(x).ContentType&"<br />")
  5.             Response.Write("file size: "&objUpload.File(x).Size&"<br />")
  6.             If objUpload.File(x).ImageWidth<0 Then
  7.                 Response.Write("invalid image!")
  8.             Else 
  9.                 Response.Write("image width: "&objUpload.File(x).ImageWidth&"<br />")
  10.                 Response.Write("image height: "&objUpload.File(x).ImageHeight&"<br />")
  11.                 If (objUpload.File(x).ImageWidth>200) Or (objUpload.File(x).ImageHeight>200) Then
  12.                     Response.Write("image to big, not saving!")
  13.                 Else 
  14.                     Call objUpload.File(x).SaveToDisk(Server.MapPath("Uploads"), "")
  15.                     Response.Write("file saved successfully!")
  16.                 End If
  17.             End If
  18.             Response.Write("<hr />")
  19.         Next
  20.         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??

Reply With Quote
  #4  
Old January 14th, 2006, 11:03 PM
baseballdude_'s Avatar
baseballdude_ baseballdude_ is offline
Expert Learner
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2005
Location: Wisconsin
Posts: 1,853 baseballdude_ User rank is Sergeant Major (2000 - 5000 Reputation Level)baseballdude_ User rank is Sergeant Major (2000 - 5000 Reputation Level)baseballdude_ User rank is Sergeant Major (2000 - 5000 Reputation Level)baseballdude_ User rank is Sergeant Major (2000 - 5000 Reputation Level)baseballdude_ User rank is Sergeant Major (2000 - 5000 Reputation Level)baseballdude_ User rank is Sergeant Major (2000 - 5000 Reputation Level)  Folding Points: 22104 Folding Title: Starter FolderFolding Points: 22104 Folding Title: Starter Folder
Time spent in forums: 1 Week 5 Days 9 h 18 m 15 sec
Reputation Power: 45
Send a message via AIM to baseballdude_ Send a message via MSN to baseballdude_ Send a message via Yahoo to baseballdude_ Send a message via Google Talk to baseballdude_
I'm sorry I missed the check image part shadow, i was so excited to see the code
Quote:
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.

Reply With Quote
  #5  
Old January 15th, 2006, 04:16 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,608 Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)  Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 12 h 53 m 47 sec
Reputation Power: 1400
Quote:
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!

Reply With Quote
  #6  
Old January 17th, 2006, 09:59 AM
MARKEDAGAIN's Avatar
MARKEDAGAIN MARKEDAGAIN is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Nov 2004
Location: Montreal
Posts: 668 MARKEDAGAIN User rank is Sergeant Major (2000 - 5000 Reputation Level)MARKEDAGAIN User rank is Sergeant Major (2000 - 5000 Reputation Level)MARKEDAGAIN User rank is Sergeant Major (2000 - 5000 Reputation Level)MARKEDAGAIN User rank is Sergeant Major (2000 - 5000 Reputation Level)MARKEDAGAIN User rank is Sergeant Major (2000 - 5000 Reputation Level)MARKEDAGAIN User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 6 Days 6 h 44 m 25 sec
Reputation Power: 24
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.

Reply With Quote
  #7  
Old January 17th, 2006, 12:09 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,608 Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)  Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325618 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 12 h 53 m 47 sec
Reputation Power: 1400
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.

Reply With Quote
  #8  
Old February 5th, 2006, 05:14 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,608 Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)