close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues


Cleanup Issue

Thread began 5/14/2012 2:59 am by neo314 | Last modified 5/17/2012 1:13 pm by neo314 | 1205 views | 9 replies |


Cleanup Cached Resized/Thumbnails on Update/Delete [SOLVED]


This issue of being able to cleanup the thumbnails when an image is deleted is really important and does not seem to be getting much attention.

I managed to accomplish it with the code below, but I HAD to set the image name to a session variable and delete the files after the update was executed and the page redirected.

The resize functions exist on the update page showing a smaller version of the uploaded image above the FILE input field.

If I try and delete the thumbnails on the form submit, above the update transaction, the thumbnails and their directories delete, but are then recreated. I'm not sure if they are recreated before or after the redirect from the update transaction, but it is like the code inside the body tag is being executed before the update transaction redirects the page.

The code I used is as follows and must be placed above the update code.

function getDirectory($path = '.', $ignore = '') {
$dirTree = array ();
$dirTreeTemp = array ();
$ignore[] = '.';
$ignore[] = '..';

$dh = @opendir($path);

while (false !== ($file = readdir($dh))) {

if (!in_array($file, $ignore)) {
if (!is_dir("$path/$file")) {

$dirTree["$path"][] = $file;

} else {

$dirTreeTemp = getDirectory("$path/$file", $ignore);
if (is_array($dirTreeTemp))$dirTree = array_merge($dirTree, $dirTreeTemp);

return $dirTree;
$ignore = array('.htaccess', 'error_log', 'cgi-bin', 'php.ini', '.ftpquota');

$dirTree = getDirectory('/your/path/here', $ignore);
// WA File Cleanup
if (isset($_SESSION['cleanup'])) {
$ignore = array('.htaccess');
$dirTree = getDirectory($_SERVER['DOCUMENT_ROOT'].'/image_cache/images/blogs', $ignore);
if (count($dirTree)) {
foreach ($dirTree as $dir => $files) {
$dirName = substr($dir,strrpos($dir,"/")+1,strlen($dir));
$filter = substr($_SESSION['cleanup'], 0, strrpos($_SESSION['cleanup'], '.'));

if (substr($dirName,0,strlen($filter)) == $filter) {

if (count($files)) {
foreach ($files as $file) {
if (($WA_DFP_UploadStatus["WA_UploadResult1"]["statusCode"] == 1) && ($_POST["exec"] != "") && ($row_WADArs['image'] != "")) // Trigger
$_SESSION['cleanup'] = $row_WADArs['image'];
Sign in to reply to this post

Jason ByrnesWebAssist

I have logged this as a feature request for data bridge, thank you for posting this.

Sign in to reply to this post


Can you shed any light on why the thumbnails are getting recreated when the resize code is within the body of the page and should not be executed before the update transaction redirects the page?

I'm thinking that something in the WA code is using output buffering. If I knew why perhaps we could make this code I have work correctly on the page submit rather than on the redirect.

I want to avoid issues like deleting a new file because the new file had the same name as the old file and similar issues. If the code could be executed on page submit, the error checking a session variable handling would be easier.

Sign in to reply to this post

Jason ByrnesWebAssist

i would suspect code placement. I would suspect that the code to delete the thumbnails comes before the code that is used to create them.

Sign in to reply to this post


Hi Jason,

I am looking for an answer here, and I think I already described this, but perhaps I did not do a good job, so let me try again.

The working scenario is that the update page is updating a record that already has an image associated with it. The update page uses resize code to display a smaller version above the file field (so the user knows what the current image is). The user inputs a new image to replace the old one. The form is submitted.

The header PHP code:

  • Loads the includes,
  • Creates the recordset for the update transaction,
  • Uploads the image,
  • Executes a conditional statement that determines if a new image has been uploaded to replace the existing one,

    • if true, deletes the thumbnails

  • Executes Update Transaction 1 which updates the image field if a new image has been uploaded,
  • Executes Update Transaction 2 which updates and other changes and redirects to the update page (so presumably none of the pages body code is executed which is where the thumbnail generation code exists)

When the page is redirected, the record is already updated, so it should load the new file name and create thumbnails for the new image, SO WHERE IS THE CODE THAT CAUSES THE OLD FILE'S THUMBNAILS TO BE RECREATED AFTER THEY ARE DELETED?

Now the page is using a framework theme, but I tried removing the framework code and the same thing happened. I have not told it to delete the old full image yet, which I will try shortly, but to avoid throwing errors, it would still be good to understand what is happening here.

The includes for the image resize and framework have remained included throughout, so when I say I removed code, I mean all the active code in the page, not the includes.

I suspect it may have something to do with output buffering from one of the includes, but it still is not completely clear.

In short, the thumbnail code is all below, and the update transaction should redirect the page before the thumbnail code executes. Any light that can be shed on why the resize code is getting executed before the update transaction redirects the page and any fix/workaround for that would be greatly appreciated.

Sign in to reply to this post

Jason ByrnesWebAssist

I'm not sure why you are so angry about this... lets take a deep breath.

I'm clear on your explanation of the issue, but to be 100% honest, I cant tell why your custom code snippet is acting the way you describe without seeing the entire code in context.

it could be any number of things, if all i have to go on is a code snippet though, all i can do is take a wild stab in the dark.

send a copy of the pages involved so I see all of the code to get a better idea of what is going on, If i can see the code, I probably tell why it is acting the way it is acting.

Sign in to reply to this post


Whoops, sorry if that seemed angry. It was not intended to. The caps were only intended for emphasis.

I was only trying to clarify because I thought I was clear that the position of the code was accounted for in my original message, so I wanted to spell out the process in (painful) detail.

In any case, I have something that works now.

I was trying to work on just the problem of cleaning up the thumbnail images. I had not included code to delete the source image yet. Doing so solves the problem.

As described, I would like to know why the resize code was being executed even though the update transaction should have redirected before that occurred. I suspect that a WA include is using something output buffering that could be important for similar issues I might encounter in the future.

Explaining the code is proving a bit larger a job than I thought, so I will post how to do it shortly.

Sign in to reply to this post


Here is a link to the tutorial on how to cleanup resized / thumbnail images generated by WA when updating or deleting a record with an image field.

It is not fully tested, but seems to be working for me so far.


Sign in to reply to this post

Jason ByrnesWebAssist

thanks for posting that.

  As described, I would like to know why the resize code was being executed even though the update transaction should have redirected before that occurred.  

i would really need to look at your pages to see the code in context to be able to determine why that is happening, your description of the code does not sound like it should do that, so without seeing the code, i don't really have anything to go on to provide an answer.

Sign in to reply to this post


At the time, I was working on the problem. I think there is enough information to recreate the problem. When I finish this project, I might try and recreate it to show you.

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





Ease of use


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...