Many Joomla administrators make the mistake by uploading all their images to the root directory of the images folder. A mistake, as they all soon discover, that can cause the media manager to crash.
At itoctopus, we have come up with a solution to this problem, and we call it: EDIJ (short for Evenly Distributing Images in Joomla – OK, that was a joke!). No seriously, we did come up with a solution a long time ago (and we use it all the time), and the solution is to evenly distribute images under the images directory based on the image’s modification date. Here’s how we do it:
- We loop through all the images under the root directory of the images folder.
-
We get the last modification date of each image (the best you can get with standard Linux is the last modification date).
-
We extract the year and the month from the modification date of that image.
-
We calculate the new path of the image (which will be something like images/[yyyy]-images/[mm]).
-
We then move (using the PHP function rename) the image from the old location to the new location.
If you want to see it in action, then you can find the script here! Yes – we’re that generous! But, before using it, please keep in mind the following:
- We don’t claim any responsibility, explicit or implicit, resulting from the use of the script. You use the script at your own risk!
-
This script modifies the filesystem and the database – so you should make sure you backup your Joomla website before running it.
-
You will need to modify the path at the end of the script to correspond with the current physical path of your Joomla website.
-
You will need to ensure that Apache has full permissions over the images directory.
-
Ideally, you should only run the script during off hours or on a staging version of your website.
-
You will need to extract the script to the root directory of your Joomla website, and then run it by pointing your browser to: http://www.yourjoomlawebsite.com/evenlyDistributeImagesJoomla.php.
-
The script will work for Joomla articles and K2 items (by default, it will work for Joomla articles, you will need to point the main function to the K2 function for it to work for K2).
-
The script will take some time, so be patient.
We understand that for non-technical persons, such a script might be a challenge. If that’s the case, then just contact us. We’ll make sure to handle this in as little time as possible and for a very, very affordable fee!