How to change directory name in php

青灯夜游
Release: 2023-03-09 07:16:01
Original
2328 people have browsed it

In PHP, you can use the rename() function to change the directory name. This function is used to rename files or directories. The syntax format is "rename(oldname,newname)". Returns TRUE if the change is successful; FALSE if it fails.

How to change directory name in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php change directory name

//修改目录
/*
 * @param  editefile   // 修改文件的方法
 * @param  jpath   // 旧的文件夹名
 * @param  xpath  // 新的文件夹名
 * @param  is_dir()  // 判断有没有就得目录
 * @param  rename() // 修改目录的函数
 */
 
function  editfile($jpath,$xpath){
 
    $_path = iconv('utf-8', 'gb2312', './Public/Uploads/' . $jpath);//旧文件名
    $__path = iconv('utf-8', 'gb2312', './Public/Uploads/' .$xpath);//新文件名
    if(is_dir($_path)){//判断有没有旧的目录
        if(file_exists($__path)==false){
            if (rename($_path, $__path))//修改目录
            {
                $value['file']='修改成功';
                $value['success']='success';
            }
            else
            {
                $value['file']='修改失败';
                $value['fail']='fail';
            }
        }else{
            $value['file']='有同级目录名相同';
            $value['fail']='fail';
        }
 
    }else{
        $value['file']='没有找到要找的目录';
        $value['fail']='fail';
    }
    return $value;
 
}
Copy after login

Related function description:

is_dir() function checks whether the specified file is a directory. Returns true if the filename exists and is a directory.

rename() function renames a file or directory. If successful, the function returns TRUE. On failure, returns FALSE.

Syntax

rename(oldname,newname,context)
Copy after login
Parameters Description
oldname Required. Specifies the file or directory to be renamed.
newname Required. Specifies the new name of the file or directory.
context Optional. Specifies the environment for a file handle. context is a set of options that can modify the behavior of the stream.

Recommended study: "PHP Video Tutorial"

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

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!