| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
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
|
||||
|
||||
|
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
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 Last edited by Shadow Wizard : August 16th, 2007 at 04:13 AM. |
|
#2
|
||||
|
||||
|
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!
__________________
www.xoise.com - www.ourfreegames.com - www.playtouchgames.com - www.randomtools.net - www.xenocide-rpg.com |
|
#3
|
|||||
|
|||||
|
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:
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?? |
|
#4
|
||||
|
||||
|
I'm sorry I missed the check image part shadow, i was so excited to see the code
![]() Quote:
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. |
|
#5
|
||||
|
||||
|
Quote:
![]() |
|
#6
|
||||
|
||||
|
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. |
|
#7
|
||||
|
||||
|
Quote:
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. |
|
#8
|
||||
|