note 68704 added to function.rename
| From: | PHP at Drarok dot com | Date: | Tue, 08 Aug 2006 08:57:50 +0000 |
| Subject: | note 68704 added to function.rename | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115625@lists.php.net to get a copy of this message | ||
As described from the unlink() page:
You have to release any handles to the file before you can rename it (True on Windows, at least).
This will NOT work, you'll receive permission denied errors:
<?php
$fileHand = fopen('tempFile.txt', 'r');
rename( 'tempFile.txt', 'tempFile2.txt' ); // Permission Denied!
?>
Simply close the handle to fix this:
<?php
$fileHand = fopen('tempFile.txt', 'r');
fclose($fileHand);
rename( 'tempFile.txt', 'tempFile2.txt' );
?>
This has me scratching my head for some time, as the handle was opened at the top of a marge
function, and the rename was at the bottom.
----
Server IP: 83.138.144.80
Probable Submitter: 62.105.115.135
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.rename.php
Edit -- https://master.php.net/note/edit/68704
Del: integrated -- https://master.php.net/note/delete/68704/integrated
Del: useless -- https://master.php.net/note/delete/68704/useless
Del: bad code -- https://master.php.net/note/delete/68704/bad+code
Del: spam -- https://master.php.net/note/delete/68704/spam
Del: non-english -- https://master.php.net/note/delete/68704/non-english
Del: in docs -- https://master.php.net/note/delete/68704/in+docs
Del: other reasons-- https://master.php.net/note/delete/68704
Reject -- https://master.php.net/note/reject/68704
Search -- https://master.php.net/manage/user-notes.php