File Management, sorry i keep changing, this is the last one! :)

08-18-03, 05:19 AM
|
|
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.
|

08-18-03, 07:46 AM
|
|
Coding Addict
|
|
Join Date: Jun 2003
Location: Maryland, US
Posts: 268
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What error are you getting?
__________________
Shane Bauer
Microsoft Certified Professional (MCP) - ASP.NET
ASP/ASP.net, C#, VB/VB.NET, PHP, Perl, SQL
|

08-18-03, 04:27 PM
|
|
Wannabe Coder
|
|
Join Date: Jul 2003
Location: BC, Canada
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Microsoft VBScript runtime error '800a01ad'
ActiveX component can't create object
/file_uploader.asp, line 5
|

08-18-03, 04:34 PM
|
|
Wannabe Coder
|
|
Join Date: Jul 2003
Location: BC, Canada
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
and for the files.asp and filelist_download.asp pages, i get this error:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
/files.asp, line 14
and for filelist_download.asp, its line 9
I have my databases all in one folder called 'databases' and the path is pointed right to it.
Last edited by Arctic; 08-18-03 at 04:37 PM.
|

08-18-03, 07:17 PM
|
|
Wannabe Coder
|
|
Join Date: Jul 2003
Location: BC, Canada
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hey Shane, i have another script i was using before, but the way it works is it uploads the files into a folder and then the download page reads all the files in the folder and lists them on the page. I want the included pictures of the upload/download pages to look the same, but is there any way to convert code into something so it will read of a database (files.mdb).
upload code: (scripts_upload.asp)
----------------------------------------------
<%
' Variables
' *********
Dim mySmartUpload
Dim file
Dim oConn
Dim oRs
Dim intCount
Dim fileCount
Dim curDir
Dim strSQL
intCount=0
' Object creation
' ***************
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
' Only allow txt or htm files
' ***************************
mySmartUpload.AllowedFilesList = "zip,exe"
' Deny physical path
' *******************
mySmartUpload.DenyPhysicalPath = True
' Only allow files smaller than 50000 bytes
' *****************************************
mySmartUpload.MaxFileSize = 5120000
' Deny upload if the total fila size is greater than 200000 bytes
' ************************************************** *************
mySmartUpload.TotalMaxFileSize = 5120000
' Upload
' ******
mySmartUpload.Upload
' Connect to the DB
' *****************
Set oConn = Server.CreateObject("ADODB.Connection")
curDir = Server.MapPath("../databases/scripts.mdb")
oConn.Open "DBQ="& curDir &";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;"
' Open a recordset
' ****************
strSQL = "SELECT FILENAME,FILE FROM TFILES"
Set oRs = Server.CreateObject("ADODB.recordset")
Set oRs.ActiveConnection = oConn
oRs.Source = strSQL
oRs.LockType = 3
oRs.Open
' Select each file
' ****************
For each file In mySmartUpload.Files
' Only if the file exist
' **********************
If not file.IsMissing Then
' Add the current file in a DB field
' **********************************
oRs.AddNew
file.FileToField oRs.Fields("FILE")
oRs("FILENAME") = file.FileName
oRs.Update
intCount = intCount + 1
End If
Next
' Display the number of files uploaded
' ************************************
Response.Write(intCount & " file(s) uploaded.<BR>")
fileCount = select count(filename) from TFiles
' Destruction
' ***********
oRs.Close
oConn.Close
Set oRs = Nothing
Set oConn = Nothing
%>
script download page: (scripts.asp)
-----------------------------------------------
<%
Dim folder, strslash, servername, scriptpath, thing, fdlm, fsize, physicalpath
folder = "scripts"
' The table shows the filename as a link, the date last modified and the file size
' Adjust the table and columns as needed. Delete columns if you don't need them
' Find out what type of server we are on and the server data
If Left(server.mappath("."),1) = "/" Then
strslash = "/"
Else
strslash = "\"
End If
servername = Request.Servervariables("server_name")
scriptpath = Request.Servervariables("script_name")
scriptpath = Mid(scriptpath,(Instrrev(scriptpath, "/")),1)
Dim filesobj, fileslist, fname, posnumright
dim f, dflm
Set filesobj = Server.CreateObject("scripting.filesystemobject")
Set fileslist = filesobj.GetFolder(server.mappath(".") & "/" & folder)
%>
<!-- ************* Table start and header row ****************-->
<br>
<center>
<table border="0" width="100%">
<tr><td align="center"><!--#include virtual="adrotator/adrotator_468x60.asp"--></td> <td><table border="0">
<tr><td valign="top"><font face="arial" size="1">If you would like to see the ad's on this web site removed, please donate!</font></td></tr>
<tr><th valign="top"><form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="snowboarderdude2003@hotmail.com">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="tax" value="0">
<input type="image" src="https://www.paypal.com/images/x-click-but04.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form></th></tr>
</table></td></tr>
<tr><th><font size="6pt">SCRIPT ARCHIVE</font></th></tr>
<tr><td align="center" valign="top">
<table width="100%" border="1" style="border-collapse: collapse" bordercolor="white">
<tr>
<td width="50%" background="download_top.jpg">Script</td><td background="download_top.jpg">Date</td><td background="download_top.jpg" width="10%">Size</td><td background="download_top.jpg" width="15%">Downloaded</td></tr>
<%
For each thing In fileslist.files
posnumright = instrrev(thing, strslash)
fname = right(thing,(len(thing)-posnumright))
Set f = filesobj.GetFile(thing)
fdlm = f.datelastmodified
If f.size > 1023 Then
fsize = CStr(CInt(f.size / 1024)) & "K"
Else
fsize = CStr(f.size) & " bytes"
End If
physicalpath = server.mappath(".")
%>
<tr>
<td>
<!-- ******* First column with link to file name ******* -->
<img src="file.gif"> <a href="http://<%=servername & scriptpath & folder & "/" & Server.HTMLEncode(fname) %>" target="_blank"><%=Server.HTMLEncode(fname)%></a>
</td>
<td>
<!-- ******* Second column with last modified date of file ***** -->
<%=Server.HTMLEncode(fdlm)%>
</td>
<td>
<!-- ******* Third column with file size ******** -->
<%= Server.HTMLEncode(fsize) %>
</td>
<td>
<!-- ******* Fourth column with # of times downloaded ******** -->
</td>
</tr>
<%
Set f = Nothing
Next
Set fileslist = Nothing
Set filesobj = Nothing
%>
<!-- *************** End of Table ****************** -->
</table>
The dl_screenshot.jpg is the download page. There are 2 more colums to the right (Size and Times Downloaded). I had to trim down the picture to 250px, grrrr. Made it look the best i could.
Last edited by Arctic; 08-18-03 at 07:25 PM.
|

08-20-03, 11:34 PM
|
|
Coding Addict
|
|
Join Date: Jun 2003
Location: Maryland, US
Posts: 268
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally posted by Arctic
and for the files.asp and filelist_download.asp pages, i get this error:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
/files.asp, line 14
and for filelist_download.asp, its line 9
I have my databases all in one folder called 'databases' and the path is pointed right to it.
|
Your database path is incorrect. Change it and try again.
__________________
Shane Bauer
Microsoft Certified Professional (MCP) - ASP.NET
ASP/ASP.net, C#, VB/VB.NET, PHP, Perl, SQL
|

08-20-03, 11:35 PM
|
|
Coding Addict
|
|
Join Date: Jun 2003
Location: Maryland, US
Posts: 268
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally posted by Arctic
Microsoft VBScript runtime error '800a01ad'
ActiveX component can't create object
/file_uploader.asp, line 5
|
The object you are trying to create on line 5 cannot be created. Make sure you are using it correctly.
__________________
Shane Bauer
Microsoft Certified Professional (MCP) - ASP.NET
ASP/ASP.net, C#, VB/VB.NET, PHP, Perl, SQL
|

08-25-03, 03:14 AM
|
|
Wannabe Coder
|
|
Join Date: Jul 2003
Location: BC, Canada
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
I dont know how to use this stuff correctly, these are downloaded scripts that i dont know to much about, i know some basics of asp but not a lot. please help me by showing me the correct way.
|

08-25-03, 12:40 PM
|
|
Coding Addict
|
|
Join Date: Jun 2003
Location: Maryland, US
Posts: 268
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
.. i know some basics of asp but not a lot. please help me by showing me the correct way.
|
I know this is not the answer you wanted to hear, but it is very hard to mentor/teach someone online. I suggest getting a book and just reading it straight through. Or, find some good online tutorials and go through them.
__________________
Shane Bauer
Microsoft Certified Professional (MCP) - ASP.NET
ASP/ASP.net, C#, VB/VB.NET, PHP, Perl, SQL
|

08-25-03, 12:54 PM
|
|
ASP Guru
|
|
Join Date: Jun 2003
Location: UK
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Arctic, this obvious but, is the Persits Upload component actually isntalled on the sever?
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|