Show only files that exist on the server

In this section of the tutorial you will enhance the form by adding a fail safe mechanism for the list. If a user deletes files from the disk, but not from the database (e.g. due to lack of space, he connects through FTP and removes old files), the entries should not appear in the list. If they do, an attempt to download them will fail, and display an error.

To hide files that no longer exist on disk, but only in the database, you can use a conditional region: the Show If File Exists server behavior accomplishes just the needed job.

To start enhancing the list, follow the next steps:

  1. Open the list page in Dreamweaver.

  2. Click on the dynamic field that retrieves the file name. This is done so that you position the cursor inside the list's table. The conditional region will not be applied only on the download link.


     

  3. Select the <tr> tag from the Tag Selector in Dreamweaver.


     

  4. Apply the Show If File Exists server behavior from the Server Behaviors tab > + > MX Kollection > Conditional Regions.

  5. Configure the user interface as shown below:

  6. Click on OK to apply the server behavior. Save the page and upload it to the server. Now if you delete a file from the server, without removing its database entry, it will no longer be displayed in the list.

As you can see in the image below, the cv.doc entry still exists in the database, but the list does not display it. Why? Because it has been manually deleted from the server's disk.