Any way to bulk rename images AND keep image links?

Need help with the Administration of your Joomla! 2.5 site? This is the spot for you.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
cgmsys
Joomla! Apprentice
Joomla! Apprentice
Posts: 38
Joined: Sun Feb 19, 2012 5:22 pm
Location: Southampton, PA USA

Any way to bulk rename images AND keep image links?

Post by cgmsys » Sun Sep 01, 2013 5:03 am

I've run into a couple of situations where the images used in a site have invalid file names (Mostly spaces). This was due to migrations from other platforms and carelessness on my part.

I started to look at page speed and ran the images through smushit.. The problem was that 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
* If I rename the files through FTP or JCE, the links are broken and I need to Re-link the image
* I have 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 used dbreplacer but I can't think of a way to only replace the spaces inside the file name.. )
* I have not been able to find any extensions that would help


I suppose it could be programmed.. ie
1. Look in the articles table
2. Look for strings ending in .jpg
3. Look for spaces in the string before the .jpg and replace with a -

Can anyone point me to a way to fix a bunch of invalid filenames without going through each article??

Fortunately the sites aren't that large but I'm looking for some efficiency.

thanks

chris

User avatar
alikon
Joomla! Champion
Joomla! Champion
Posts: 5941
Joined: Fri Aug 19, 2005 10:46 am
Location: Roma
Contact:

Re: Any way to bulk rename images AND keep image links?

Post by alikon » Sun Sep 01, 2013 6:35 am

i think if you have an image name pattern (the bad one)

you could use an mysql query something like this

Code: Select all

 UPDATE #_content
          SET  fulltext   = REPLACE(introtext, 'the bad one', 'the dood one');
           
          WHERE  fulltext   LIKE '%the bad one%'
Nicola Galgano
i know that i don't know
www.alikonweb.it

cgmsys
Joomla! Apprentice
Joomla! Apprentice
Posts: 38
Joined: Sun Feb 19, 2012 5:22 pm
Location: Southampton, PA USA

Re: Any way to bulk rename images AND keep image links?

Post by cgmsys » Sun Sep 01, 2013 2:35 pm

Alikon - Thanks for the reply.

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.

So, my plan is

1. Run an akeeba backup of the site.
2. Ftp down the image files.
3. Manually rename the image files by replacing spaces with a -. I could use a bulk renamer but the number of files is manageable. THen run the images through Smushit to compress them
4. Run DB replacer to replace %20 with - in the content table
5. Delete the images on the server with FTP.
6. Re-upload the images with the correct file names.

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.

chris

User avatar
alikon
Joomla! Champion
Joomla! Champion
Posts: 5941
Joined: Fri Aug 19, 2005 10:46 am
Location: Roma
Contact:

Re: Any way to bulk rename images AND keep image links?

Post by alikon » Sun Sep 01, 2013 4:57 pm

i've forgot taht the content table have the fulltext field too
Nicola Galgano
i know that i don't know
www.alikonweb.it

cgmsys
Joomla! Apprentice
Joomla! Apprentice
Posts: 38
Joined: Sun Feb 19, 2012 5:22 pm
Location: Southampton, PA USA

Re: Any way to bulk rename images AND keep image links?

Post by cgmsys » Tue Sep 03, 2013 2:05 pm

Alikon

THanks.. Dbreplacer wasn't working as expected so I used an sql statement.

Code: Select all

UPDATE `josxxx_content`  set introtext=replace(`introtext`, '%20', '-') WHERE 1
There was nothing in the fulltext field so I didn't bother with that. The replace did break one anchor link that had a space in it but that was fine.

thanks again for the pointers.

One warning for anyone who tries something like this.. BE SURE TO BACK UP YOUR SQL TABLES before attempting any mass changes via sql.


chris


Locked

Return to “Administration Joomla! 2.5”