Reputation: 14575
How can I duplicate a php file that I already created and place it into a different directory when a user pushes the submit button
Upvotes: 6
Views: 2683
Reputation: 455272
You can use the copy
function as:
if ( copy($srcFilename,$destPath) ) {
// file copied.
} else {
// error occurred..call error_get_last() function for err details.
}
Few things to note:
If the destination file exists,
copy
will overwrite it. If you don't
want this you can check the existence
of the destination file using
file_exists
function before you
copy.
Both the parameters of copy must be
files. In Linux we usually do: cp
file dir
to copy the file file
into the directory dir
with the
name file
. This will not work with
copy
.
Some hosting companies disable copy
function for security reasons. In
that case you can implement your own
copy by reading the file using
file_get_contents
and
writing to the file using
file_put_contents
. Since you want to copy PHP scripts (which are not very large memory wise) this will work fine.
Upvotes: 16