Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 436
Product
FileUp
Title
Upload Files to a User-Defined Sub-Directory
Solution

You may want to let your users select a subdirectory on the server in which to store their uploaded file. For example, you might want to let a user select a folder name from a listbox before uploading. However, when you use the selected folder name in your upl.path assignment, the result may surprise you. Your file may end up in C:\winnt, or you may get an NTFS permissions error.

If you reference FileUp’s Form property before you set the Path property, FileUp will default to c:\winnt or your system directory. Think of the Path property as a pre-setting of the upload. The Form property, or any property that requests data, will start the process without any pre-setting. So, it is not a good idea to use the Form property before setting the Path property. MaxSize, which defines the maximum size of the file uploaded, is another property that must be set before referencing any form data.

The Path property sets the directory for the temporary file created, when the file reaches the server. The SaveAs method sets the final destination directory on the server. With SaveAs, you can include form data in the path. In fact, this is the best means to set the listbox form element value as a different directory or subdirectory.

<%
'--- Incorrect way

folder = upl.form("Subdirectory")
upl.Path = "c:\inetpub\wwwroot\upload\" & folder & "\"
%>

'---------------------------------------------

<%
'--- Correct way

'--- Any directory with property permission can be used here for the temporary
'--- file folder.
'--- In this example, we are using the root of the destination path only.
upl.Path = "c:\Upload\"

'--- The subdirectory is defined via the Form element- "Subdirectory"
folder = upl.form("Subdirectory")

'--- To get the original file name, we parse out the filename.
Filename = Mid(Upl.UserFilename,InstrRev(Upl.UserFilename,"\")+1)

'--- Define the destination
upl.SaveAs "c:\Upload\" & folder & "\" & Filename
%>

Created : 12/1/2002 12:00:00 AM (last modified : 8/14/2002 2:57:34 PM)
Rate this article!
 
Comments