Jump to content

best way to update image extension in database?


phpnoobie9

Recommended Posts

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?

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
}
?>

Archived

This topic is now archived and is closed to further replies.

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