Today’s article, we will show you how to copy a file from folder to another by using PHP. For this we use default PHP function copy
. Basically, it has two parameters to work a copy function. This file will overwrite if the file already exists in the folder.
See the below example function.
<?php $file = '/var/www/html/example.txt'; $newfile = '/var/www/html/example.txt.bak'; if (!copy($file, $newfile)) { echo "failed to copy $file"; }else{ echo "copied $file into $newfile"; } ?>
Did this post help you?
Tutsplanet brings in-depth and easy tutorials to understand even for beginners. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.
Leave a Reply