Thoughts, information and reflections about technology

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.

In summary

  • 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. 

The method of fixing the spaces was 

  1. Run an akeeba backup of the site. Also, my host takes daily snapshots. 
  2. Run the repair and optimize from Admin tools to make sure there are no problems with the database. 
  3. Ftp down the image files.
  4. 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. 
  5. 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. 
  6. 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. 
  7. Delete the images on the server with FTP. 
  8.  Re-upload the images with the correct file names.
UPDATE `joslbi_content`  set introtext=replace(`introtext`, ‘%20’, ‘-‘) WHERE 1


That should work 100 percent. If anything goes wrong I could always reload from the akeeba backup or the daily server images my host makes. 

Similar Posts:

No tags for this post.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact me
Recent Comments