close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Showing and then deleting files on the server

Thread began 8/17/2009 11:41 am by dave172661 | Last modified 8/17/2009 6:08 pm by Jason Byrnes | 1378 views | 2 replies |

dave172661

Showing and then deleting files on the server

Hi,

I just purchased DFP2 and already own DataAssist and was wondering how to do the following with it.

Show all images contained within a directory on the server with thumbnails and have a delete check box next to item so that they can be deleted.

Here's why!

i designed an admin back end for a client so that they can manage their items in the store. They have options to upload the images for the product etc, BUT they requested that they have a delete function for when they don't want a particular product image anymore. Same goes with when they would like to select an image they have already uploaded to the server, How do we display a list of images contained within the directory on the server when the filename is contained within the product details table along with all the other product fields.

So how do i do this? Would i create a function within the product update page seeing as this is where they upload the images seems logical to place the remove image option here also or do i create a separate page for the sole purpose of managing product images?

Anyone with any ideas would be appreciated.

Cheers

Sign in to reply to this post

anonymous

Dave,

There are couple of ways to do this, but I'll go through the way I have done a similar application.

The first thing to do is to get the contents of the image folder (this is assuming that all images are located in the same folder).

You can use a PHP function "scandir('imagefolderhere')" to learn about what is contained in a particular folder. You could create an array first, such as:

$mynewimagearray = scandir('imagefolder');



After doing that, you could loop through the results - but make sure you only accept results that are truly images - because remember, there will be hidden "notes" files in there, as well.

To make sure you loop through image files only, you could run something like the getimagesize command on each item in the loop. Running getimagesize is nice because it will return the boolean value of FALSE if the item is not an image and therefore cannot be read by getimagesize.

So within the loop of array items you would create an if statement. If the Boolean value is TRUE - meaning that getimagesize actually reads the image and can get values you will let it display to the browser, as such:

$checkifimage = getimagesize['$arrayitem']; 
if ($checkifimage) {
echo "<img src="yourimage">";
}



Now the code above is the most basic form... I would probably close out the PHP tags so I could just add basic HTML between and include the checkbox beside each item like this:

if ($checkifimage) } ?>

ADD WHAT EVER YOU WANT HERE... just remember that all PHP variable will have to be inside a PHP tag set

<?php } ?>



You could put your check box then right beside the image output and then wrap the entire thing inside a form. You could then make the value of the checkboxes - if checked - equal to the array item itself as that is also providing the name for the image source.

To, turn the images into thumbnails, you will need to use a script that does thumbnails on the fly. There are several out there and your image source name will change to look something like this:

<img src="resizescript.php?filename=$arrayItem&width=100&height=100">



Please note that the code above is arbitrary and just happens to be similar to code I used before where the $arrayItem is the actual image being resized by the script and the width and height attributes tell the script what dimensions to resize to.

The final step would be to get all the values checked and store them into an array - then loop through that array with the Digital File Pro delete behavior added into the loop so that it deletes each specified file.

Sign in to reply to this post

Jason ByrnesWebAssist

You could add the Delete file server behgavior to the Delete record page created by DataAssist, or on the update record page created by DataAssist.

You could also create a separate page that lists out all of the Files that are in the database and give a delete file button.

In either case, the way to make it work will be to crate a form with a hidden form element, and a submit button.

The init value of the hidden form element will be the ID for the product table.

You then create a recordset that filters the product table on the hidden form element.

When you apply the delete file server behavior, set the trigger to the Record set not being empty. For the file name, click the lightning bolt and select the File name column from the recordset you created.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...