Jump to content

[SOLVED] Help, How to change batch of *.bmp to *.jpg in database


cTak

Recommended Posts

Hello, I am helping a friend setup an eCommerce store with Zen cart, he added all of the products and uploaded the images, but a lot of them are .bmp files. 

I have downloaded them and converted them to web friendly jpgs, but the database is still calling for the .bmp files.

 

Anyone have an SQL code I can use to update the "product_images" coulum so that *.bmp is changed to *.jpg?

 

Something like this, but this does not work because there is a filename in front of the extension.

UPDATE zen_products SET products_image = "jpg" WHERE products_image = "bmp"

 

 

Thanks!

Link to comment
Share on other sites

Showing rows 0 - 29 (3169 total, Query took 0.0005 sec)  
SQL query: 
SELECT REPLACE (
`products_image` ,
'.gif',
'.jpg'
)
FROM zen_products
LIMIT 0 ,
30  

 

I did what you said bubblegum.anarchy, it shows the first 30 rows changed, but it doesn't save the changes?  What do I do from here?

Link to comment
Share on other sites

Use the UPDATE statement (backup the table first):

 

UPDATE zen_products SET products_image = replace(products_image, '.gif', '.jpg')

 

Strictly speaking, that's not very robust, since that substring could appear anywhere in the products_image string (although unlikely) -- hence my suggestion of a regex.

Link to comment
Share on other sites

Strictly speaking, that's not very robust, since that substring could appear anywhere in the products_image string (although unlikely) -- hence my suggestion of a regex.

 

Yes, off coarse fenway - I recently developed a habit of naming images with dot seperators like btn.edit.gif so an image named btn.giffer.gif would end up being named btn.jpgfer.jpg - but as you suggest, unlikely.

 

MySQL really should apply full regular expressions so something like UPDATE table SET value = REGEXP '/(.+)\.gif$/\1.jpg/i' could be performed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.