Web | This Site

Learning PHP
Advanced PHP
PHP Function Reference
PHP Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM

| Home |  | References |  | Discussion Forums |  | About TP

# 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

Parameter | Description
--- | ---
source | Path to the source file.
dest | The 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";
    }
    ?>

Advertisement

Online Image Processing

Indian Baby Names