Be the first to write a review
FREE! Building A File Upload and Rating Application Support
Following on from his free tutorial on building a Content Management System with Server Behaviours and the Advanced HTML Editor, Matt shows how build a site that allows users to upload their own files, and rate those files. There's also a password-protected moderator's area so that you can be sure that all files can be checked before being made "live".
This free tutorial is suitable for beginners and uses only built-in Dreamweaver server behaviors and the DMXzone Pure ASP/ ASP.NET Upload Extensions! The uploading element is also PHP compatible, but the "rating" system doesn't work with PHP since it has no Command behavior to do the rating with.
Building Uploaderadmin.asp
As with our previous application, this page acts as an area for moderators to approve and edit information before it goes live. It works behind the scenes, not seen by users, only by the people who administrate the site.
The basic layout follows a similar process to the uploaderview.asp page we just created. It's a table with a repeat Region server behavior and a Recordset containing all columns from our cms_uploads table.
The big differences are the Live?, Edit and Delete table columns. Live simply contains the Y/N character from the live column of our recordset. EDIT is a link to uploaderedit.asp and has a parameter of id set to the recordset column of id. DELETE is a link to uploaderdelete.asp, with an identical parameter.
You should restrict access to this page using a User Authentication > Restrict Access To Page behavior. The dialog is pretty simple:
We simply restrict access based on username and password, and set the page to send unwanted users out to uploaderlogin.asp.
Building uploaderedit.asp
This page contains the facility for the moderator to edit the details a user has created for their uploaded file.
Again we create a Recordset called item. This selects every column from the cms_uploads table, and is filtered to only take the row that corresponds to the id provided in the link on the previous page.
We then create a basic update form:
For each of the non-filename columns (except rating) we create a form element to hold its current value. For live we use a checkbox, which is set to a dynamic value taken from our recordset. Highlight the form element and click on the Dynamic button in the Properties panel to bring up the relevant dialog:
Once you have sorted these details, add an Update Record server behavior:
Again, add a User Authentication > Restrict Access behavior, so people can't alter items without a password. With this file finished, save it and close.
The uploaderdelete.asp page
This final page deletes records from our database, and removes uploaded files.
Again create a recordset called item, which gets the id, title and name from the cms_uploads table. Again filter the recordset by the id URL Parameter.
Create a page layout like the one below:
It contains a simple form with a delete button and some text to check that the user didn't accidentally click on the delete link.
Using the Bindings panel, add the title column to the page in place of the item text, so that the user is sure which item is being deleted.
Add a Delete Record server behavior, using the item recordset and bound to your form. Set the behavior to send the user back to the admin page when the delete is finished.
After adding the delete behavior click + > DMXZone > Delete File Before Record .
If you stored only the filename, and not the full path in the database, you'll need to browse to the relevant directory. Since we're storing the complete path, we can just set the behavior to delete the file at the path specified in the name recordset column. This means we don't get files hanging around after we've removed their details from the database.
As before, add a Restrict User Access behavior to keep just anybody from deleting items. Close the file and save it.
Matt Machell
A man of many talents, Matt has been a web designer, technical editor, and jewellery picker. He is currently on contract for the Birmingham City University, producing pages for research centres.
He has tech-edited a dozen books on web design and development for glasshaus, Apress and Sitepoint.
He likes music with loud guitars and games with obscure rules.
His website can be found at: http://www.eclecticdreams.com
He lives in Birmingham with his girlfriend, Frances, and a horde of spider plants.