...

View Full Version : Help!!!!how to save data about accessing uploaded files to database?



davincith
09-18-2007, 05:57 PM
I write search files webpage.when users enter part or all of a file name and asp page send back a list of only the files(that user can click to open files) whose names contain the text they entered.I want to save data about accessing files such as file name ,accessed date of fileto my database(Microsoft Access) after user click to open the file.I don't know how to write a adding code to do this.


This my asp code.please tell me how to solve.


<%
Dim strPath ' Path of directory to search
Dim objFSO ' FileSystemObject variable
Dim objFolder ' Folder variable
Dim objItem ' Variable used to loop through the
'contents of the folder

Dim strQuery ' Search string

' You could just as easily read this from some sort of input,
' but I don't need you guys roaming around our server so
' I've hard coded it to a directory I set up to illustrate
' the sample.
' NOTE: As currently implemented, this needs to end with the /
strPath = "c:\uploaded files"

' Retrieve the search string. If empty it will return all files.
strQuery = Request.QueryString("query")

' Show our search form and a few links to some sample searches
' Create our FSO and get a handle on our folder
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))

' Show a little description line and the title row of our table
%>
<p>
Contents of <strong><%= strPath %></strong> that match your query:
</p>

<table border="5" bordercolor="green" cellspacing="0" cellpadding="2">
<tr bgcolor="#006600">
<td><font color="#FFFFFF"><strong>File&nbsp;Name:</strong></font></td>
<td><font color="#FFFFFF"><strong>File&nbsp;Size:</strong></font></td>
<td><font color="#FFFFFF"><strong>Date&nbsp;Created:</strong></font></td>
</tr>
<%
' Now come the part where we find the files whose names match the string
' passed in part. It's relatively straightforward. We simply loop through
' the objFolder.Files collection and check each file's name to see if it
' matches. Note that I'm not going to look for SubFolders that match our
' search string. You can easily include them if you like. Just use
' objFolder.SubFolders. The syntax is the same as it is for files.
For Each objItem In objFolder.Files
' I'm using a case insensitive search. If you want case sensitivity
' then change vbTextCompare to vbBinaryCompare
If InStr(1, objItem.Name, strQuery, vbTextCompare) <> 0 Then
%>
<tr bgcolor="#CCFFCC">
<td align="left" ><a href="<%= strPath & objItem.Name %>"><%= objItem.Name %></a></td>
<td align="right"><%= objItem.Size %></td>
<td align="left" ><%= objItem.DateCreated %></td>
</tr>
<%
End If
Next 'objItem

' All done! Kill off our object variables.
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
</table>

miranda
09-18-2007, 09:29 PM
Instead of opening the file directly send the user to an intermediary page which handles the saving of info to the DB. You can pass the path and file name to the intermediary page as parameters in the querystring. then after you have saved the information you can open the file

davincith
09-19-2007, 02:40 AM
Instead of opening the file directly send the user to an intermediary page which handles the saving of info to the DB. You can pass the path and file name to the intermediary page as parameters in the querystring. then after you have saved the information you can open the file

I have to quite change the code in this part

For Each objItem In objFolder.Files
' I'm using a case insensitive search. If you want case sensitivity
' then change vbTextCompare to vbBinaryCompare
If InStr(1, objItem.Name, strQuery, vbTextCompare) <> 0 Then
%>
<tr bgcolor="#CCFFCC">
<td align="left" ><a href="<%= strPath & objItem.Name %>"><%= objItem.Name %></a></td>
<td align="right"><%= objItem.Size %></td>
<td align="left" ><%= objItem.DateCreated %></td>
</tr>
<%
End If
Next 'objItem


right? to sent path and file name to intermediary page.Could you tell me the code that i must to edit the upper code and the intermediary,please
I am not quite sure to write a correct code.I am quite beginner

miranda
09-19-2007, 03:00 PM
The more I think about this, you would be much better served by having a table in the database to hold all of the files that people can access. Then you can query the db for the list of files and point to the intermediary page with a single parameter (the primary key from this table)

Change the hyperlink to the name of some other asp page. Then pass the key to this as a parameter. This is done by putting a question mark after the .asp then have the parameter name with an equal sign and then the value of the parameter. For multiple parameters you need to include an ampersand for each subsequent parameter name so the final string when printed out will look like this
somepage.asp?item=327&qty=2&color=red

then on the intermediary asp page, you will open a connection to the db, then add a record to the table that shows the number of downloads of the item, then open the table that stores the location of the download on your server and get the path to the download and then using either server.transfer or response.redirect move the user to the download file.

If you are indeed a beginer then visit these sites to learn the basics of programming asp pages http://www.w3schools.com/asp/default.asp
http://www.learnasp.com/freebook/asp/
http://www.4guysfromrolla.com/webtech/ASP_INDEX_98.shtml <- stick to articles written from 98 to 2000 as new content is about .net
http://www.codeproject.com/asp/

davincith
09-20-2007, 02:35 PM
you can query the db for the list of files and point to the intermediary page with a single parameter (the primary key from this table)


you mean change data type of Field "File Name" from text to hyperlink that set to point to the intermediary page(in database file(.mdb)),right?



Change the hyperlink to the name of some other asp page. Then pass the key to this as a parameter. This is done by putting a question mark after the .asp then have the parameter name with an equal sign and then the value of the parameter. For multiple parameters you need to include an ampersand for each subsequent parameter name so the final string when printed out will look like this
somepage.asp?item=327&qty=2&color=red

You mean the intermediary page?
I don't understand how to pass the key to parameter that you say.Could you write example code? Please


P.S. Sorry for my stupid question.I have not asp experience enough.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum