国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

php move, copy and delete files

When we deal with files every day, we can delete files, rename files, or copy files.

In this section, we will explain some of the most commonly used operations in our daily lives.

Let’s talk about renaming first. The renaming function is:

Rename file

bool rename($old name,$new name);

This function returns a bool value to change the old name to the new name.

<?php
   //舊文件名
   $filename = 'test.txt';

   //新文件名
   $filename2 = $filename . '.old';

   //復(fù)制文件
   rename($filename, $filename2);
?>

We open the directory and we can see the effect. You will find that the specified file is copied to the target path.

Copy files

Copying files is equivalent to cloning technology, cloning an original thing into a new thing. The two look exactly the same.

bool copy(source file, target file)

Function: Copy the source file with the specified path to the location of the target file.

Let’s play it through experiments and code:

<?php
   //舊文件名
   $filename = 'copy.txt';

   //新文件名
   $filename2 = $filename . '_new';

   //修改名字。
   copy($filename, $filename2);
?>

Summary:
You will find that there is an extra file through the above example.

Delete file

Deleting a file means deleting a file in the specified path, but this deletion is direct deletion. If you are using a Windows computer, you cannot see this file in the Recycle Bin.

You will only find that this file has disappeared.

bool unlink(file with specified path)

<?php
   $filename = 'test.txt';

   if (unlink($filename)) {
       echo  "刪除文件成功 $filename!\n";
   } else {
       echo "刪除 $filename 失敗!\n";
   }
?>
Continuing Learning
||
<?php //舊文件名 $filename = 'copy.txt'; //新文件名 $filename2 = $filename . '_new'; //修改名字。 copy($filename, $filename2); ?>
submitReset Code