The file upload function can be realized by using component or component-less upload technology in ASP. From this, we can use ASP's componentless upload technology to establish a virtual FTP server on our own website. Like a real FTP server, we can provide remote file management for multiple users . At the same time, each user can only operate their own document.
When a file is uploaded, ASP can use FSO or database to save the file data (some servers do not provide FSO function). Here I use a database to save files uploaded by users. I won’t go into the advantages of using a database, but there are many. Another reason is that IIS limits the size of file uploads (probably a maximum of 200KB). Using the database method, you can use resuming technology to break through this limit, and you can upload very large files , very large, infinitely large, etc.
*****************
(Haha, I talked a lot of nonsense. Let’s first talk about the principles and methods of implementation, and then talk about the method of using software to implement it)
*****************
● Step 1: Create a database on the server (ACCESS, SQL-SERVER, MYSQL are all acceptable), the simpler one is ACCESS. Create two tables in the database:
Upload user management: admin (ID, Name, Password, Type)
Save uploaded file data: files (ID, ParentID, FileName, FileLength, FileType, FileData, UpDate, UserID).
If FileLength=0, it means it is a folder, and a root folder is created for each user.
● Step 2: Create a user login page and use SESSION to save the user's ID to limit their operations on files.
Session("Name") = list("SName")
Session("UID") = list("ID")
● Step 3: Create user home page (display files uploaded by users)
strSQL = "SELECT * FROM files WHERE ParentID=" & userRootID ' userRootId is the ID of the user's root folder
strSQL = strSQL & " AND UserID=" & SESSION("UID")
strSQL = strSQL & " ORDER BY FileName"
● Step 4: Upload file page list.AddNew
list("ParentID") = userRootID
list("FileName") = Form("Name")
list("FileLength") = Form("Length")
list("FileType") = Form("Type")
list("FileData").AppendChunk MidB(sdata,Form("Start"),Form("Length"))
list("UserID") = Session("UID")
list("UpDate") = Now()
list.Update
● Step 5: File management operations (use the file ID to identify the file and restrict user operations)
Delete: "DELETE * FROM files WHERE ID=" & iID & " AND UserID=" & Session("UID")
Download: "SELECT * FROM files WHERE ID=" & iID & " AND UserID=" & Session("UID")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open myConnStr
Set list = conn.Execute("SELECT * FROM files WHERE ID=" & iID & " AND UserID=" & Session("UID"))
If NOT list.EOF Then
If list("FileLength") > 0 Then
Response.AddHeader "Content-disposition", "inline; filename=" & list("FileName")
Response.ContentType = list("FileType")
Response.Binarywrite(list("FileData").GetChunk(list("FileLength")))
End If
End If
● Just complete some other auxiliary operation pages. Of course, due to browser limitations, the file upload resume technology cannot be used directly and can only be implemented through client software . There is a software on the Internet called "Upload File Manager" (including ASP source code), which implements the above functions. Below we will discuss how to use this software to create our own virtual FTP server.
Software download address: http://www.blue999.com/webfiles/uploadfiles_setup.exe
***************
(It’s very complicated. Keep it simple. Let’s take a look at how to use the “Upload File Manager” to implement a virtual FTP server.)
***************
● 1. After downloading and installing the software, upload the ASP file provided with the software to the website using FTP software (such as uploading to webfiles)
● 2. Execute the client software and set the server path to the uploaded folder. The username and password of the super administrator are both admin.
● 3. Perform user management, add, delete, modify, enable/disable, and limit the size of files uploaded by users.
● 4. OK, the virtual FTP server is established, and all users manage their files through the software (on the client). The software operates similarly to an explorer.
● 5. The software also provides ASP source code of some application examples. You can check it out yourself.