note 19504 added to function.copy
| From: | jacob at keystreams dot com | Date: | Fri, 01 Mar 2002 05:00:46 +0000 |
| Subject: | note 19504 added to function.copy | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27216@lists.php.net to get a copy of this message | ||
A function that performs various checks before copying:
function file_copy($file_origin, $destination_directory, $file_destination, $overwrite, $fatal) {
if ($fatal) {
$error_prefix = 'FATAL: File copy of \'' . $file_origin . '\' to
\'' . $destination_directory . $file_destination . '\' failed.';
$fp = @fopen($file_origin, "r");
if (!$fp) {
echo $error_prefix . ' Originating file cannot be read or does not exist.';
exit();
}
$dir_check = @is_writeable($destination_directory);
if (!$dir_check) {
echo $error_prefix . ' Destination directory is not writeable or does not exist.';
exit();
}
$dest_file_exists = file_exists($destination_directory . $file_destination);
if ($dest_file_exists) {
if ($overwrite) {
$fp = @is_writeable($destination_directory . $file_destination);
if (!$fp) {
echo $error_prefix . ' Destination file is not writeable [OVERWRITE].';
exit();
}
$copy_file = @copy($file_origin, $destination_directory . $file_destination);
}
} else {
$copy_file = @copy($file_origin, $destination_directory . $file_destination);
}
} else {
$copy_file = @copy($file_origin, $destination_directory . $file_destination);
}
}
--------------
Example Usage:
$copy = file_copy("/path/to/original.file", "/path/to/",
"destination.file", 1, 1);
--
http://www.php.net/manual/en/function.copy.php
http://master.php.net/manage/user-notes.php?action=edit+19504
http://master.php.net/manage/user-notes.php?action=delete+19504
http://master.php.net/manage/user-notes.php?action=reject+19504