Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

copy

Description

Copies file

Syntax

copy ( string $source , string $dest [, resource $context ] ) : bool

Parameters

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.

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

context

A valid context resource created with stream_context_create().

Return

Returns TRUE on success or FALSE on failure.

Examples

1 · source dest

<?

$source = 'file.php';
$dest = 'file2.php';

$return = copy($source, $dest);

if ($return) {
    echo "copied $source to $dest";
} else {
    echo "failed to copy $source";
}

?>
copied file.php to file2.php

2 · context

<?

$options = array(
    'http' => array(
        'method' => "GET",
        'header' => "Accept-language: en\r\n" . "Cookie: cookie=test\r\n"
    )
);

$source = 'file.php';
$dest = 'file2.php';
$context = stream_context_create($options);

$return = copy($source, $dest, $context);

if ($return) {
    echo "copied $source to $dest";
} else {
    echo "failed to copy $source";
}

?>
copied file.php to file2.php
HomeMenu