copyFile.php
Table of Contents
Functions
- copyFile() : bool
- Copies a single file to a destination path.
Functions
copyFile()
Copies a single file to a destination path.
copyFile(string $source, string $destination[, bool $overwrite = true ][, bool $createDirectory = true ]) : bool
Unlike copyFilteredFiles() (which mirrors a whole directory tree), this helper copies one file with explicit, typed error handling:
- the source is validated with assertFile() (must exist and be readable);
- if
$destinationis an existing directory, the file is copied inside it, keeping the source basename (thecp source dir/convention); - copying a file onto itself is refused (it would truncate the source);
- when
$overwriteisfalse, an existing destination raises a FileException; - the destination's parent directory is created on demand when
$createDirectoryistrue.
Parameters
- $source : string
-
Path to the source file to copy.
- $destination : string
-
Destination file path, or an existing directory to copy into.
- $overwrite : bool = true
-
Whether to overwrite an existing destination file (default:
true). - $createDirectory : bool = true
-
Whether to create the destination directory if missing (default:
true).
Tags
Return values
bool —Returns true on success.