Tuesday, 27 August 2013

PHP Function copy()

Syntax

bool copy ( string $source, string $dest );

Definition and Usage

Makes a copy of the file source to dest.
Warning: If the destination file already exists, it will be overwritten.

Paramters

ParameterDescription
sourcePath to the source file.
destThe destination path. If dest is a URL, the copy operation may fail if the wrapper does not support overwriting of existing files.

Return Value

Returns TRUE on success or FALSE on failure.

Example

Following is the usage of this function:
<?php
$file = '/usr/home/guest/example.txt';
$newfile = '/usr/home/guest/example.txt.bak';

if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";
}else{
    echo "copied $file into $newfile\n";
}
?>

No comments:

Post a Comment