OctoberCMS Media Manager Fix

Posted on

The web is a very particular at times and for us developers, there are things that go unspoken, some “golden rules” that are so obvious to us that we forget that sometimes, the other species who share the world with us, regular humans, will also interact with systems we develop.

Please, before you get all defensive (if you are a regular human) or big-headed (if you are a developer), both of us have qualities and flaws, we are not better than each other, we are just … different.

Anyways – I should cut back on my coffee before writing.

Developers all know the rule – files for the web should never contain spaces or special characters. Even though file systems have gone a long, long way since ’em good ol’ days, where file names were 9 characters long. Nowadays, you could actually write a tweet and save it as a file name.
This flexibility has spread unevenly, with legacy systems interacting with modern systems, and the web, well, it’s not a place for the faint of heart.

As developers, we should worry about file names and their compatibility. As users, our world peers also worry about filenames but in a different context, and that is when things go boom.

OctoberCMS is a beautiful little piece of software for any PHP developer (if you don’t know it – I urge you to have a look)[http://octobercms.com]
I love it and use it for pretty much anything I can. From internal little projects to huge projects serving content to ~25K concurrent users, I’ve done it all, yet, one small oversight on my behalf cost me a sleepless weekend of troubles.

I decided to use October’s built-in Media Manager to handle all my CMS related images. All was fine during testing phases, but, when we put the system online, and actual regular humans started feeding the, literally hundreds of thousands of images into the system we started facing a series of issues with special characters and spaces in filenames causing all sorts of glitches on our client’s site.

After some digging and a lot of pain, sweat, and tears, I eventually wrote a little script that would rename the existing files in the system.

It was then that I decided that I needed to avoid this happening again and that I would write some code I could use in my next projects to mitigate this issue. Rather than having a personal library script, I wrote out a small plugin you can add to your OctoberCMS installation that will rename the files you upload to your media manager, to a web-friendly name.

There are still a few little options I’d like to add to the plugin, but, none of them will be breaking changes. Feel free to give it a test-drive and leave me a comment if you have any suggestions, criticism or what not.

The link for the plugin is here:
https://octobercms.com/plugin/gregorybrown-mediamanagerfix

Leave a Reply

Your email address will not be published.