Home > Backend Development > PHP Problem > How to modify file extension in php

How to modify file extension in php

藏色散人
Release: 2023-03-05 16:40:01
Original
3202 people have browsed it

How to modify the file extension in php: first create a PHP file; then define a "changeTypeName" method; then obtain the absolute path of the file; and finally modify it through "rename($fileRealPath, $compressCssFileRealPath);".

How to modify file extension in php

Recommended: "PHP Video Tutorial"

php Change the suffix name of the file in the file directory

changeTypeName("E:/bak/video/code/views", "html", "phtml");
 
//改变文件目录下文件的后缀名
function changeTypeName($path, $oldTypaName, $newTypeName)
{
    $path = "glob://$path/*";
    $files = new DirectoryIterator($path);
    foreach ($files as $file) {
        $fileRealPath = $file->getRealPath(); //文件绝对路径
        $compressCssFileRealPath = str_replace(".$oldTypaName", ".$newTypeName", $fileRealPath);
        rename($fileRealPath, $compressCssFileRealPath);
    }
}
Copy after login

The above is the detailed content of How to modify file extension in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template