Welcome Guest, Not a member yet? Register   Sign In
resize and unlink file question
#1

On my resize function. I am trying to unlink with my width and height size add on to the new file.

When it creates a new file it stores it in my images > cache folder and then addes width and height on to it.

example_100x50.jpg but the original file would be example.jpg the original files are located in images > catalog

If the example.jpg file is not there in folder then I need to be able to unlink that image but because it has the width and height added on to it I do not know how to make sure it unlinks correct one.

Question how could I unlink the correct cache image even though it has width and height different to the original image


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

    $old_file FCPATH 'images/' $filename;

    $extension pathinfo($filenamePATHINFO_EXTENSION);

    $extended_image substr($filename0strrpos($filename'.')) . '_' $width 'x' $height '.' $extension;
        
    $new_file 
FCPATH 'images/cache/' $extended_image;

    // Checks if file does not exist in images folder but exist in cache will remove it.

    $check_if_file_is_set array_reverse(glob(FCPATH  'images/catalog/*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}'GLOB_BRACE));

    for ($i=0$i count($check_if_file_is_set); $i++) { 
        if ($i sizeof($check_if_file_is_set)) {
                
        $file 
str_replace(FCPATH 'images/'''$check_if_file_is_set[$i]);

            if (!file_exists(FCPATH 'images/' $file)) {
                // unlink(FCPATH . 'images/cache/' . $some_variable);
            }
        }
    }

    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();

    }

    $ouput_image '';

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

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


Messages In This Thread
resize and unlink file question - by wolfgang1983 - 02-25-2016, 02:32 AM
RE: resize and unlink file question - by Diederik - 02-25-2016, 03:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB