phpnoobie9 Posted March 26, 2008 Share Posted March 26, 2008 I have about 100 images in mysql that has an md5 name and are jpgs. I want to change the jpg to gif. What's the best way to do this? SELECT image FROM mytable....then I'm lost. Link to comment https://forums.phpfreaks.com/topic/97895-best-way-to-update-image-extension-in-database/ Share on other sites More sharing options...
soycharliente Posted March 26, 2008 Share Posted March 26, 2008 Do you have a list of each image? You could run a for loop with PHP to loop through the list of images and say something like: UPDATE `table` SET `image`='MD5($imagegif)' WHERE `image`='MD5($imagejpg)' Link to comment https://forums.phpfreaks.com/topic/97895-best-way-to-update-image-extension-in-database/#findComment-500875 Share on other sites More sharing options...
phpnoobie9 Posted March 26, 2008 Author Share Posted March 26, 2008 Alright I ran a loop with the list of image names. So....I should take those and...somehow put all of them in the $imagejpg variable and convert those to $imagegif variable?..then md5 them again? Is there a way for me to just edit the last 3 characters of each name? Link to comment https://forums.phpfreaks.com/topic/97895-best-way-to-update-image-extension-in-database/#findComment-500882 Share on other sites More sharing options...
phpnoobie9 Posted March 26, 2008 Author Share Posted March 26, 2008 I was able to find that all the jpgs had similiar endings and was able to change all of them over using find and replace on dreamweaver. Thanks. Link to comment https://forums.phpfreaks.com/topic/97895-best-way-to-update-image-extension-in-database/#findComment-500888 Share on other sites More sharing options...
soycharliente Posted March 26, 2008 Share Posted March 26, 2008 If you're storing the MD5 hash of the filename, you can't just change the last 3 characters. Unless it's actually stored as something that looks like 3847a9bc97d0e97.jpg I'm assuming that you hashed the entire filename including the extension. You'd have something LIKE this: <?php $list = array('one', 'two', 'three'); // the file names without the extensions foreach ($list as $pic) { $imagejpg = $pic.".jpg"; $imagegif = $pic.".gif"; $sql = "UPDATE `table` SET `image`='MD5($imagegif)' WHERE `image`='MD5($imagejpg)'"; // run the query } ?> Link to comment https://forums.phpfreaks.com/topic/97895-best-way-to-update-image-extension-in-database/#findComment-500893 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.