View Single Post
  #1 (permalink)  
Old 08-18-03, 04:19 AM
Arctic Arctic is offline
Wannabe Coder
 
Join Date: Jul 2003
Location: BC, Canada
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
File Management, sorry i keep changing, this is the last one! :)

I dont understand why these pages wont work. Can you look over them and show me where my mistakes are?
(The database is attached, dl it if you need to look at the tables in it or something)

Code:
==============================================
Im not sure about the Persits.Upload part, im not sure if i need to change it or not.

(file_uploader.asp)
-------------------------
<HTML>
<BODY>

<%
Set Upload = Server.CreateObject("Persits.Upload")

' we use memory uploads, so we must limit file size
Upload.SetMaxSize 5120000, True
Upload.AllowedFilesList "exe,zip"

' Save to memory. Path parameter is omitted
Count = Upload.Save

' Obtain file object
Set File = Upload.Files("THEFILE")

If Not File Is Nothing Then
' Build ADO connection string
Connect = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("../databases/files.mdb")

' Use ADO Recordset object
Set rs = Server.CreateObject("adodb.recordset")

' Optional: check whether this file already exists using MD5 hash
Hash = File.MD5Hash
rs.Open "SELECT * from TFiles WHERE Hash='" & Hash & "'", Connect, 2, 3
If Not rs.EOF Then
Response.Write "This file already exists in the database."
Response.End
End If
rs.Close

' Reopen recordset to insert file
rs.Open "TFiles", Connect, 2, 3

rs.AddNew
rs("File") = File.Binary
rs("filename") = File.FileName
rs("filesize") = File.Size
rs("hash") = Hash
rs("description") = Upload.Form("DESCR")
rs.Update

Response.Write "File saved."
Else
Response.Write "File not selected."
End If
%>

</BODY>
</HTML>
----------------------------------------

Here is the download code: (files.asp)
---------------------------------------
<HTML>
<BODY>

<h3>Click on a link to download file from the database:</h3>

<%
' Build ADO connection string
Connect = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("../databases/files.mdb")

' Use ADO Recordset object
Set rs = Server.CreateObject("adodb.recordset")

' Reopen recordset to list all files
rs.Open "TFiles", Connect, 2, 3

Count = 0
While Not rs.EOF
Response.Write "<A HREF=""filelist_download.asp?id=" & rs("id") & """>"
Response.Write Trim(rs("filename"))
Response.Write "</A><BR>"
rs.MoveNext
Count = Count + 1
Wend

Response.Write "<P>Total files in the database: " & Count
%>

</BODY>
</HTML>
----------------------------------------------------------

Page that downloads the file: (filelist_download.asp)
--------------------------------------------------------------------
<%

' The file must not contain any HTML tags, not even HTML comment tags <!-- ...-->

' Build ADO connection string
Connect = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("C:\WINDOWS\Desktop\Arctic\webserve r\wwwroot\databases\files.mdb")

Set db = Server.CreateObject("ADODB.Connection")
db.Open Connect

SQL = "SELECT * FROM TFiles where id = " & Request("id")
Set rs = db.Execute( SQL )
If rs.EOF Then Response.End
Response.ContentType = "application/octet-stream"

' Let the browser know the file name
Response.AddHeader "Content-Disposition", "attachment;filename=" & Trim(rs("filename"))

' Let the browser know the file size
Response.AddHeader "Content-Length", CStr(rs("filesize"))

' Send actual file
Response.BinaryWrite rs("file")
%>
--------------------------------------------------------

Note to Shane:
If you read this im sorry about all the scripts i have gone throught, you finally helped me on the Radio button changer script, i got that working, but all the scripts and editing i have to them, whenever i would try and upload a file there was always an error. So this is the last script im trying. Please be able to help me with this. Im tired of all these upload/download scripts. Like half of my time spent on building my site has been the upload/download part. grrrrrrrrrrr. heh.
Attached Files
File Type: zip files_db.zip (83.2 KB, 334 views)
__________________
http://www.streamsearch.ca - Live stream search engine. Find radio stations to listen to and TV channels to watch!

http://www.machonemedia.ca - Mach One Media web development and media services.
Reply With Quote