How can I add the missing file extensions to a folder of image files (png, jpg, etc) which have no file extension?
What I have below loops through the image directory and echos the mimetype (just for info’s sake), and then loops through the directory again and attempts to add the appropriate file extension. I’m following How can I change a file’s extension using PHP?
But no file extension is added.
Issue 1: $mime_type
echos as image/png, image/jpeg ; how do I echo simply png or jpg for the replace_extension
function?
Issue 2: why does the replace_extension
function not work in this case?
$dir = "/Sites/imagetest/*";
foreach(glob($dir) as $file)
{
$mime_type = mime_content_type($file);
echo $mime_type;
echo '<br>';
}
foreach(glob($dir) as $file)
{
if (($pos = strrpos($file , '.')) !== false) {
$file = substr($file, 0, $pos);
}
return $file . '.' . $mime_type;
}