Home  >  Article  >  Backend Development  >  What is the purpose of php copy() function?

What is the purpose of php copy() function?

怪我咯
怪我咯Original
2017-07-13 17:39:583057browse

copy() Function in php is mainly used to copy files. Its syntax is as follows

copy(source,destination)

ParametersDescriptionsourceRequired. Specifies the files to be copied. destinationRequired. Specifies the destination for copied files.
You can use the copy function to achieve the download function! ! !

Copy local files, specific examples are as follows:


$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

Remote files

$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'
}


With just a few lines of code like this, PHP can easily solve file copying, copying or moving functions!

Isn’t it very simple!



The above is the detailed content of What is the purpose of php copy() function?. 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