Can copy() in php copy a directory?

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

copy() cannot copy directories. The copy() function can only copy files. It can copy (copy) a file to the specified directory. If the target file already exists in the specified directory, it will be overwritten; the syntax is "copy (path of the source file to be copied, Target path)", returns TRUE if the copy is successful, and returns FALSE if it fails.

Can copy() in php copy a directory?

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, DELL G3 computer

The copy() function cannot copy the directory , this function can only copy files.

сoру() function can copy (copy) a file to the specified directory. It returns TRUE if the execution is successful and FALSE if it fails. The syntax format of the function is as follows:

copy(string $source, string $dest)
Copy after login

The parameter description is as follows:

  • $source: the path of the source file to be copied;

  • $dest: target path. If the file exists, it will be overwritten. If $dest is a URL, if the encapsulation protocol does not support overwriting existing files, the copy will fail;

Example: Copy the test.txt file to the img directory and rename it to newtest.txt

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$file    = &#39;test.txt&#39;;
$newfile = &#39;img/newtest.txt&#39;;
if(copy($file, $newfile)){
    echo &#39;文件复制成功!&#39;;
}else{
    echo &#39;文件复制失败!&#39;;
}
?>
Copy after login

Can copy() in php copy a directory?

Can copy() in php copy a directory?

Note:

  • The copy() function in PHP does not work with remote files. It only works on files accessible to the server's file system.

  • If the target file already exists, it will be overwritten.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Can copy() in php copy a directory?. 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