Page 1 of 1

Sort image by date upload in Image Manager

Posted: Sat Aug 29, 2015 10:42 am
by opencartnewbie_vn
I want to sort image by date upload in Imang Manager Opencart 1.5.x by fix in PHP code.
Anyone know the way to do this.
Thanks so much

Re: Sort image by date upload in Image Manager

Posted: Sat Aug 29, 2015 4:51 pm
by opencartnewbie_vn
Up :( :( :(

Re: Sort image by date upload in Image Manager

Posted: Sat Aug 29, 2015 9:58 pm
by straightlight
Hi,

that is an interesting request. In admin/controller/common/filemanager.php file,

find:

Code: Select all

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

Code: Select all

usort($directories, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
Reversed order (if needed):

Code: Select all

usort($directories, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
This should resolved the ordering list.

Source: http://stackoverflow.com/questions/1249 ... rt-by-date

Re: Sort image by date upload in Image Manager

Posted: Sun Aug 30, 2015 5:53 pm
by opencartnewbie_vn
I'm so sorry but I can not find this line in admin/controller/common/filemanager.php file

Code: Select all

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

Re: Sort image by date upload in Image Manager

Posted: Sun Aug 30, 2015 9:39 pm
by straightlight
For 1.5x releases, this would be the line to track on the same controller file:

Code: Select all

$directories = glob(rtrim(DIR_IMAGE . 'data/' . str_replace('../', '', $this->request->post['directory']), '/') . '/*', GLOB_ONLYDIR);

Re: Sort image by date upload in Image Manager

Posted: Wed Sep 30, 2015 5:32 pm
by seorniyc
Hi ;

I have same problem. I have many folders named 1501 , 1502 .... 1550.. I upload new products images on folder and when i add products photo go to last page, select folder....

I want change sort order to desc. If i see last folder in first i add very easy.

Straighlight this fix not working in 2.0.0.31

can you help me ?

Thanks

straightlight wrote:Hi,

that is an interesting request. In admin/controller/common/filemanager.php file,

find:

Code: Select all

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

Code: Select all

usort($directories, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
Reversed order (if needed):

Code: Select all

usort($directories, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
This should resolved the ordering list.

Source: http://stackoverflow.com/questions/1249 ... rt-by-date

Re: Sort image by date upload in Image Manager

Posted: Thu Oct 01, 2015 6:57 am
by straightlight
Straighlight this fix not working in 2.0.0.31

can you help me ?
Yes, by describing exactly what you mean by not working, a possible solution could be provided on that end.

Re: Sort image by date upload in Image Manager

Posted: Fri Oct 02, 2015 9:46 pm
by seorniyc
Dear straightlight ;

I try your fix, but not change order. I add new folders but they are going to last. Not first.

Re: Sort image by date upload in Image Manager

Posted: Fri Oct 02, 2015 9:51 pm
by straightlight
In the same file,

find:

Code: Select all

$files = glob($directory . '/' . $filter_name . '*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}', GLOB_BRACE);
add after:

Code: Select all

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

Re: Sort image by date upload in Image Manager

Posted: Sat Oct 03, 2015 4:09 pm
by seorniyc
straighlight

thanks for reply but nothing to change. its sort by name asc.

actually i need only sort reverse. if i can sort name desc. i use easyly.

thanks.

Re: Sort image by date upload in Image Manager

Posted: Sat Oct 03, 2015 7:20 pm
by straightlight

Code: Select all

usort($files, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
Reversed order ...

Re: Sort image by date upload in Image Manager

Posted: Mon Oct 05, 2015 3:44 pm
by seorniyc
straightlight wrote:

Code: Select all

usort($files, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
Reversed order ...

Dear straightlight ;

Thanks again, but nothing change. still the files and folders sort by name , sort order asc .

You try this code ? is that work ?

Whats wrong can you look ? filemanager.php attach.

Thanks.

Re: Sort image by date upload in Image Manager

Posted: Thu Oct 08, 2015 8:32 am
by straightlight
The reason why the sort order is not applying the change on the image list is because the file dates is not included in the array from the controller. In order to re-order the list, the file added date the images has been uploaded must be captured as well. Otherwise, the order will never change.

Re: Sort image by date upload in Image Manager

Posted: Sat Dec 26, 2015 7:02 am
by rmandiga
Worked for me. changed the code and clicked on modifications for refresh.

Now images showing up in reverse order.

Looking to remove pagination to have all images to scroll down.


Thanks Straight !!!

Re: Sort image by date upload in Image Manager

Posted: Fri Jul 15, 2016 12:18 am
by coldrex
rmandiga wrote:Worked for me. changed the code and clicked on modifications for refresh.

Now images showing up in reverse order.

Looking to remove pagination to have all images to scroll down.


Thanks Straight !!!
Exactly what I need also. Any news?

Re: Sort image by date upload in Image Manager

Posted: Sat Aug 20, 2016 9:57 am
by gilles85
straightlight wrote:For 1.5x releases, this would be the line to track on the same controller file:

Code: Select all

$directories = glob(rtrim(DIR_IMAGE . 'data/' . str_replace('../', '', $this->request->post['directory']), '/') . '/*', GLOB_ONLYDIR);
Thank you mate it works :)