Thursday, August 4, 2016

Sort image by date upload in Image Manager in opencart

In admin/controller/common/filemanager.php file,

find

$files = glob(rtrim($directory, '/') . '/*');

replace with
usort($directories, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));

reverse order
usort($directories, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));


For directory

$directories = glob($directory . '/' . $filter_name . '*', GLOB_ONLYDIR);

replace with
usort($directories, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));

reverse order

usort($directories, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));

1 comment:

  1. please note it shouldnot be 'replace with'
    it should be add after it
    so the resault should be like this

    $directories = glob($directory . '/' . $filter_name . '*', GLOB_ONLYDIR);
    usort($directories, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));

    ReplyDelete