ASP Component Building Page 3
Here we show what we want the component to handle and how
the code should work.
Server.ScriptTimeOut = 200 'increase the time out for larger files
Set uploadme = server.CreateObject("bobd.bobdupload") 'create our object
'First we want to have the ability to control the types
'of files being uploaded. We are going to give 2 ways to control
'the file uploads, bobdadd_illegal_file and bobdadd_legal_file.
'Both will take file types delmited'by commas.
'If bobdadd_legal_file is set it allows only the those files to be uploaded.
'If bobdadd_illegal_file is set it files with those ext will be blocked.
'In a real world situation, only one of these two would be used
uploadme.bobdadd_illegal_file "exe, asp" ' block *.exe, *.asp
uploadme.bobdadd_legal_file "doc, htm" 'allow only *.doc, *.htm
'We want to give the ability to have default settings for some important
'properties. This allows us to set a standard and not have to set them everytime
'the component is used. It also allows administration to have a control in
'site management. The directory to store and if you are going to overwrite
'existing files will allow defaults thru the following two methods. These would only
' have to be set once and also could be set by making a registry entry. Any
'Directory setting can be either a physical or a virtual directory.
uploadme.bobdSetDir = "C:\files"
uploadme.bobdSetDir = "myweb"
uploadme.bobdSetOverWrite = false
'These two values could also be set on an as
needed basis by the following
'2 methods. These 2 override the values in the registry
uploadme.bobdDirectory = "c:\files"
uploadme.bobdOverWrite = TRUE
'We also want to add the ability to have a
posting item contain the value
'of the receiving directory, so that we can have user interaction. This property is set
'to the NAME of the input item of the posting form which will contain the directory
uploadme.aspRequestDir = "txt2"
'Give the ability to view the raw code being
sent. This is great to
'see and understand the data being sent and received.
uploadme.aspDebug = true
'And the method that actually does the file work
'The upload method returns 2 collections, the bobdFileNames and
'the bobdRequestParts. The bobdFileNames collections has 2 methods
'and 6 properties. Again it is a collection so iteration is allowed.
For each item in
response.write "File Name is " & _
uploadme.bobdfilenames(item).fName & "<br>"
response.write "File orig dir is " & _
uploadme.bobdfilenames(item).fOrigDir & "<br>"
response.write "File save dir is " & _
uploadme.bobdfilenames(item).fSaveDir & "<br>"
response.write "File length is " & _
uploadme.bobdfilenames(item).fLength & "<br>"
response.write "File extention is " & _
uploadme.bobdfilenames(item).fExt & "<br>"
response.write "File state is " & _
uploadme.bobdfilenames(item).fstate & "<br>"
'Most of the properties are self explanatory except for 1
'The file state shows if the file was stored, the component will not
'cast an error on I/O errors. This is so that in a multiple file upload,
'the component will store as many files as possible. The asp page
'will need to check to see if the file store was completed.
'The 2 file methods are remove(to delete the
uploaded file) and
'Move(which ,moves(renames) the file. Both return values of true
if uploadme.bobdfilenames(item).move("c:\movedir") then
response.write "The file was moved!"
response.write "File Move failed!"
if uploadme.bobdfilenames(item).remove then
response.write "The file has been deleted"
response.write "File delete failed!"
'bobdRequestParts collection contain what you would normally
'access by Request(item). When doing the file upload we
'have do a binaryread, which makes the request collection
'invalid. The bobdRequestParts replaces the standard
my_name = uploadme.asprequestparts("t1")
my_size = uploadme.asprequestparts("t3")
Now that we know what we want the component to do
lets code it