copy
Description
The copy of Filesystem for PHP 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
Links
Filesystem
- basename
- chgrp
- chmod
- chown
- clearstatcache
- dirname
- disk_free_space
- disk_total_space
- diskfreespace
- fclose
- feof
- fflush
- fgetc
- fgetcsv
- fgets
- file
- file_exists
- file_get_contents
- file_put_contents
- fileatime
- filectime
- filegroup
- fileinode
- filemtime
- fileowner
- fileperms
- filesize
- filetype
- flock
- fnmatch
- fopen
- fpassthru
- fputcsv
- fputs
- fread
- fscanf
- fseek
- fstat
- ftell
- ftruncate
- fwrite
- glob
- is_dir
- is_executable
- is_file
- is_link
- is_readable
- is_uploaded_file
- is_writable
- is_writeable
- lchgrp
- lchown
- link
- linkinfo
- lstat
- mkdir
- move_uploaded_file
- pathinfo
- pclose
- popen
- readfile
- readlink
- realpath
- realpath_cache_get
- realpath_cache_size
- rename
- rewind
- rmdir
- set_file_buffer
- stat
- symlink
- tempnam
- tmpfile
- touch
- umask
- unlink