Hey folks,

Since I last added my improved upload behavior to the bakery, I've
made some more improvements to the code.  The last piece of the puzzle
is getting my beforeDelete to work.  When I remove an image from the
database, I also want to remove it from the file system, and it's
associated thumbnails.

For example, if I upload image_0245.jpg, I also create 3 thumbnails:
thumb.small.image_0245.jpg
thumb.medium.image_0245.jpg
thumb.large.image_0245.jpg

The below code is what I have, but I cannot get it to delete the images:

// FIXME: This currently does not delete images :(
function beforeDelete(&$model)
    {
        if(count($this->__fields) > 0)
        {
            $model->read(null, $model->id);
            if (isset($model->data))
            {
                foreach($this->__fields as $field=>$options)
                {
                    $file = $model->data[$model->name][$field];
                    if(is_file($file))
                    {
                        $dir=$options['dir]';
                        $folder = &new Folder($dir);
                        $files =
$folder->find('[a-zA-Z0-9]+x[a-zA-Z0-9]+.'.basename($file));
                        foreach($files as $f) unlink($dir.$f);
                        if (!unlink($file))
                            return false;
                    }
                }
            }
        }
        return true;
    }

$options['dir] is files/images (under the webroot dir) and as far as I
can work out, the regex should work, but seems not to be as the files
are being left on the filesystem.

Can anyone help?

--
Tane Piper
http://webrocket.wordpress.com

This email is: [ ] blogable [ x ] ask first [ ] private

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to