note 37082 deleted from function.copy by tomsommer
| From: | tomsommer@php.net | Date: | Wed, 21 Jul 2004 16:06:57 +0000 |
| Subject: | note 37082 deleted from function.copy by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73819@lists.php.net to get a copy of this message | ||
Note Submitter: m@densityonline.com
----
Some servers may produce errors when you try to copy into a folder with an existing file in there
already. Instead of overwriting the file, you may get "PERMISSION DENIED" error messages.
In order to solve the problem, I ran a file_exists() function to check if there are any existing,
matching files inside the destination folder. If so, then we delete the file first (using the
unlink() function) before we perform the copy() operations into the destination folder.
Eg:
$source_file = "path/to/source/file";
$destination_file = "path/to/destination/file";
if (file_exists($destination_file))
{
unlink ($destination_file);
}
copy ($source_file, $destination_file);
-mike tee-