close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Cleanup Issue

Thread began 5/13/2012 11:59 pm by neo314 | Last modified 5/17/2012 10:13 am by neo314 | 2495 views | 9 replies

neo314

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

Hi,

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.

<?php
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);
}
}
}
closedir($dh);

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

$dirTree = getDirectory('/your/path/here', $ignore);
*/
?>
<?php
// 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) {
unlink($dir."/".$file);
}
}
rmdir($dir);
}
}
}
unset($_SESSION['cleanup']);
}
if (($WA_DFP_UploadStatus["WA_UploadResult1"]["statusCode"] == 1) && ($_POST["exec"] != "") && ($row_WADArs['image'] != "")) // Trigger
{
$_SESSION['cleanup'] = $row_WADArs['image'];
}
?>

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