Removing spaces from filenames in Joomla sites
I’ve run into a situations where the images used in a site have invalid file names (Mostly spaces). This was due to migrations from other platforms and the fact that earlier platforms such as Frontpage were lax with filenaming.
I started to look at page speed and ran the images through smushit.. Smushit returns the compressed images with a + replacing spaces in the file name. If I try to rename the files through FTP or JCE, the link to the image is broken.
- I have invalid file names for my images
- I am using smushit to compress the files and it changes spaces to +’s
- The + is an invalid character according to JCE (Joomla Content Editor)
- If I rename the files through FTP or JCE, the links are broken and I need to Re-link the image
- I had not been able to find a means of changing the file names in a batch which means going through a site article by article
- I have not been able to find any Joomla extensions that would help
I took a closer look at the database through phpmyadmin.. If I look at the content table, I see that spaces in the links are represented as %20. That makes life easier. For some reason, I thought that the spaces in the filename would be stored as spaces.
- Be sure to have a solid backup.
- Be aware that you might break some things such as anchor links or links to external sites.
- USE THIS TECHNIQUE AT YOUR OWN RISK
The method of fixing the spaces was
- Run an akeeba backup of the site. Also, my host takes daily snapshots.
- Run the repair and optimize from Admin tools to make sure there are no problems with the database.
- Ftp down the image files.
- Use a Windows app called “Bulk Rename Utility” to rename the files. Uncheck everything but Replace. Put a space in the replace field and a – in the With field.
- THen run the images through Smushit to compress them. I was having trouble getting Smushit to recognize folders so I had to upload each folder.
- Now the trick was to replace the spaces in the image names in the Joomla content table. The article content is located in FULLTEXT and INTROTEXT. In my case, I only had data in the introtext. I found the appropriate table in phpmyadmin. Once you have the correct table, choose the SQL tab. The code shown below worked for me. Keep in mind that %20 is the code for a space and that I only had to look at the introtext field. If you have links in your category descriptions then you would need to modify those tables as well.
- Delete the images on the server with FTP.
- Re-upload the images with the correct file names.
- CLEAR YOUR SERVER AND BROWSER CACHES AND CHECK YOUR SITE THOROUGHLY.
UPDATE `joslbi_content` set introtext=replace(`introtext`, ‘%20’, ‘-‘) WHERE 1
- An example of why you should use the featured image feature in WordPress
- A quick way to clear the redirect list in Joomla
- Fabrik for joomla 2.1 to 3.x migration.
- Adding icons for editing, deleting and saving records in Ruby on Rails
- DB Replacer – Mass changes for your Joomla Site
- How to prevent hotlinking with Frontpage published sites.
- Removing obsolete database tables from your Joomla site.
- You must enable html multi for file uploads.