- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
copy() function in PHP
The copy() function copies a file. A copy of the source file to the destination file gets created. if the destination file is already present, it gets overwritten.
Syntax
copy(source_file, dest_file)
Parameters
source_file − Set the file to copy
dest_file − Set the file to copy to
Return
The copy() function returns.
- TRUE, on success
- FALSE, on failure
Example
<?php echo copy("D:/myfiles/sourcefile.dat","D:/myfiles/destfile.dat"); ?>
Output
true
Let us see another example now.
Example
<?php $file = '/usr/home/guest/example.txt'; $newfile = '/usr/home/guest/example.txt.bak'; if (!copy($file, $newfile)) { echo "failed to copy $file...
"; } else { echo "copied $file into $newfile
"; } ?>
Output
failed to copy /usr/home/guest/example.txt...
Advertisements