Welcome Guest, Not a member yet? Register   Sign In
How to unlink file if exist in one folder but not another?
#1

I have got a resize function as shown in code below.

When it creates a new image it stores it in the images/cache/some_other_folder etc. It can be stored in multiple sub folders in my cache.

PHP Code:
$new_file FCPATH 'images/cache/' $filename

$new_file would return something like

PHP Code:
string 'C:\wamp\www\project-2-upload/images/cache/catalog/windows_7_matrix-wallpaper-2400x1350.jpg' (length=90

Question: How ever if the cache image file exist but does not exist in the $old_file path then it should remove/unlink from the cache folders


Any suggestions and examples?


PHP Code:
public function resize($filename$width$height) { 
    $this->load->library('image_lib');

    $old_file FCPATH 'images/' $filename;
    $new_file FCPATH 'images/cache/' $filename;

    if (!is_file($new_file) || (filectime($old_file) > filectime($new_file))) {

        if (!is_dir($old_file)) {
            @mkdir(FCPATH 'images/cache/'dirname($filename), 0777);
        }
            
        $config
['image_library'] = 'gd2';
        $config['source_image'] = $old_file;
        $config['maintain_ratio'] = FALSE;
        $config['width'] = $width;
        $config['height'] = $height;
        $config['new_image'] = $new_file;

        $this->image_lib->clear();
        $this->image_lib->initialize($config);
        $this->image_lib->resize();

    }

    return base_url('images/cache/' $filename);

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB