php rename file extension

When come to Linux it is case sensitive. How do you set all your file extension in the same case.

Below is the code how I rename the file extension all from .JPG (does not matter what is the original) to .jpg

<?php


function replace_extension($filename, $new_extension) {
     $info = pathinfo($filename);

    $newname = $info['filename'] . '.' . $new_extension;
    rename('/home/image/'.$filename, '/home/image/'.$newname);
    return $newname;

}

$dir = '/home/image';
$files = scandir($dir);

//print_r($files);

foreach($files as $key => $file)
{
     echo replace_extension($file, 'jpg');
    echo "<br />";
}

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *