Home > Backend Development > PHP Tutorial > php copy()函数有什么用

php copy()函数有什么用

PHPz
Release: 2020-09-05 11:43:44
Original
1235 people have browsed it

php copy()函数有什么用

php copy()函数

copy()函数用于复制文件;如果成功则返回 TRUE,如果失败则返回 FALSE。

语法:

copy(file,to_file)
Copy after login

参数:

  • file 必需。规定要复制的文件。

  • to_file 必需。规定复制文件的目的地。

注:如果目标文件已存在,将会被覆盖。

示例1:拷贝本地文件

$file_path='file/pdf/20170811.pdf';
$to_file_path='down/pdf/20170811.copy.pdf';
if(copy($file_path,$to_file_path)){
 echo 'copy ok';
}else{
 echo 'error';
}
Copy after login

示例2:拷贝远程文件

$file_url='php.cn/xx/f1.mp4';
$local_file_path = 'file/mp4/f1.mp4';
if(copy($file_url,$local_file_path)){
  echo 'down ok';
}else{
  echo 'error'
}
Copy after login

这样简单的几行代码,php就能轻松的解决文件复制,拷贝或移动等功能哈!

更多相关知识,请访问 PHP中文网!!

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