Rank: Advanced Member
Groups: Member, Administration, Moderator Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
Here is sample for Software Artisans FileUp in ASP: Code:<%
' Aurigma Image Uploader Sample Script
' WWW: http://www.aurigma.com
Server.ScriptTimeout = 450
'Modify this block, according to your needs.
Dim strGalleryPath, strConnectionString, MyConnection
'This variable specifies a relative path to the folder, where image gallery is located.
'Don't forget to add slash at the end of the path
strGalleryPath = "../Gallery/"
'Connection string to database with image descriptions
strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("../DB/Demo.mdb") & ";"
'Create Connection
Set MyConnection = Server.CreateObject("ADODB.Connection")
MyConnection.Open strConnectionString
'We delete all files and descriptions for old files
Dim objFileSystem, objFolder, objSubFolder, objFile
Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject")
'Delete source images
Set objFolder = objFileSystem.GetFolder(Server.MapPath(strGalleryPath))
For Each objFile In objFolder.Files
objFileSystem.DeleteFile objFile.Path, True
Next
'Delete thumbnails
Set objFolder = objFileSystem.GetFolder(Server.MapPath(strGalleryPath) & "\Thumbnails")
For Each objFile In objFolder.Files
objFileSystem.DeleteFile objFile.Path, True
Next
'Delete descriptions from database
MyConnection.Execute "DELETE FROM [File]"
'Process upload
Dim objUpload
Dim intFileCount, I
Dim strAuthor
'We create aspSmartUpload object for uploading images
Set objUpload = Server.CreateObject("SoftArtisans.FileUp")
objUpload.MaxBytesToCancel = 20971520
objUpload.Path = Server.MapPath(strGalleryPath)
'We create command for adding items in database
Dim MyCommand
Set MyCommand = Server.CreateObject("ADODB.Command")
MyCommand.ActiveConnection = MyConnection
MyCommand.CommandText = "INSERT INTO [File](Name, Width, Height, Author, Description) " & _
"VALUES (?, ?, ?, ?, ?)"
'Add parameters to collection
Dim ParameterName, ParameterWidth, ParameterHeight, ParameterAuthor, ParameterDescription
Set ParameterName = MyCommand.CreateParameter("Name", 200, 1, 50)
MyCommand.Parameters.Append ParameterName
Set ParameterWidth = MyCommand.CreateParameter("Width", 3, 1)
MyCommand.Parameters.Append ParameterWidth
Set ParameterHeight = MyCommand.CreateParameter("Height", 3, 1)
MyCommand.Parameters.Append ParameterHeight
Set ParameterAuthor = MyCommand.CreateParameter("Author", 200, 1, 50)
MyCommand.Parameters.Append ParameterAuthor
Set ParameterDescription = MyCommand.CreateParameter("Description", 200, 1, 255)
MyCommand.Parameters.Append ParameterDescription
'Set Author parameter value
ParameterAuthor.Value = objUpload.Form("Author")
'Total amount of uploaded files
intFileCount = objUpload.Form("FileCount")
'We run over uploaded images and load it
For I=1 To intFileCount
'Fetch source images and save it to disk
Set objFile = objUpload.Form("SourceFile_" & I)
Dim strFileName, strNewFileName
strFileName = objFile.ShortFilename
strNewFileName = strFileName
'Check whether file with such name already exists and if so,
'construct safe filename name (to avoid collision)
Dim J
J = 1
While objFileSystem.FileExists(Server.MapPath(strGalleryPath & strNewFileName))
strNewFileName = J & "_" & strFileName
J = J + 1
Wend
strFileName = strNewFileName
objFile.SaveAs (Server.MapPath(strGalleryPath & strFileName))
'Fetch thumbnails and save it to disk
Set objFile = objUpload.Form("Thumbnail1_" & I)
objFile.SaveAs (Server.MapPath(strGalleryPath & "Thumbnails/" & strFileName & ".jpg"))
'Save description in database
ParameterName.Value = strFileName
ParameterDescription.Value = objUpload.Form("Description_" & I)
ParameterWidth.Value = objUpload.Form("Width_" & I)
ParameterHeight.Value = objUpload.Form("Height_" & I)
MyCommand.Execute
Next
'Clean up
MyConnection.Close
%>
Edited by user Friday, May 23, 2008 4:16:12 PM(UTC)
| Reason: Not specified |
Best regards, Fedor Skvortsov
|