How to copy a file from one directory to another using PHP? How to copy a file from one directory to another using PHP? php php

How to copy a file from one directory to another using PHP?


You could use the copy() function :

// Will copy foo/test.php to bar/test.php// overwritting it if necessarycopy('foo/test.php', 'bar/test.php');


Quoting a couple of relevant sentences from its manual page :

Makes a copy of the file source to dest.

If the destination file already exists, it will be overwritten.


You could use the rename() function :

rename('foo/test.php', 'bar/test.php');

This however will move the file not copy


copy will do this. Please check the php-manual. Simple Google search should answer your last two questions ;)