How can I change a file's extension using PHP?

前端 未结 11 2125
清歌不尽
清歌不尽 2020-12-10 00:43

How can I change a file\'s extension using PHP?

Ex: photo.jpg to photo.exe

11条回答
  •  醉话见心
    2020-12-10 01:15

    Just replace it with regexp:

    $filename = preg_replace('"\.bmp$"', '.jpg', $filename);
    

    You can also extend this code to remove other image extensions, not just bmp:

    $filename = preg_replace('"\.(bmp|gif)$"', '.jpg', $filename);
    

提交回复
热议问题