Development

Mass renaming images in PHP

Lets say you have a group of photos from a location, shoot or event. They will be named depending on the camera something like DC001984 or IMG_02891 something like that anyway.

There is no real organisation and certainly no indicator to what they are without viewing the thumbnail. Here is some PHP code to mass rename the images which is perfect if you’re going to mass upload them and want the name to be reflective for what the image are of.

The code is this:

";//Some optional output
}

Looping through all the images in the stated directory and renaming (using rename()) to what the $context is whilst adding the count value to the end of the file name to avoid “duplicates”.

Take this example of before:

php mass rename before

to then after:

php mass rename after

 

 

Then you can pick through the photos that will be used for SEO purpose and rename them to be more specific and identifying. Otherwise you now have photos that are named relevant and organised so much better than the default file naming.

Share

Recent Posts

Kennington reservoir drained drone images

A drained and empty Kennington reservoir images from a drone in early July 2024. The…

1 year ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

1 year ago

FTP getting array of file details such as size using PHP

Using FTP and PHP to get an array of file details such as size and…

2 years ago

Creating Laravel form requests

Creating and using Laravel form requests to create cleaner code, separation and reusability for your…

2 years ago

Improving the default Laravel login and register views

Improving the default Laravel login and register views in such a simple manner but making…

2 years ago

Laravel validation for checking if value exists in the database

Laravel validation for checking if a field value exists in the database. The validation rule…

2 years ago