Home  >  Article  >  Backend Development  >  How to change the folder name in php

How to change the folder name in php

藏色散人
藏色散人Original
2021-05-20 10:13:453531browse

How to modify the folder name in php: First create a PHP sample file; then rename the html folder to cache through "rename("html","cache");".

How to change the folder name in php

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

How to change the folder name in php?

You can use php, the rename() function to rename files or directories.

If successful, the function returns true. On failure, returns false.

The command format is:

bool rename ( string oldname, string newname [, resource context] )

The specific application of rename is demonstrated below. The file location is as shown in the figure:

How to change the folder name in php

Achievement purpose:

  • Rename cache.txt to rename.txt;

  • Rename cache2.txt to cache3.txt

  • Rename the html directory to cache

  • Transfer the file directory to the html directory (renaming can be achieved)

The code is as follows:

 <?php
    $file = "html/cache.txt";
    $rename = "html/rename.txt";
  if(rename($file,$rename)){
  echo "更名成功";
  }else{
    echo "更名失败";
  }
  rename("html/cache2","html/cache3.txt");
  rename("html","cache");
  rename("file","html/files");
 ?>

Recommended learning: "PHP Video Tutorial"

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

Statement:
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