PHP rename() directory acces denied on windows (xampp) despite correct chmod & file path
I know there are thousands of questions with similar issue, however most of them got resolved by either using chmod or they just didn't provide the full path for the new name.
I'm trying to change the cache purging behaviour of some website, because when a full purge is done, the website hangs for a good amount of time (it uses a glob & recursive function to delete each file, and there are tens of thousands of them, if not more).
The main idea is to just rename the directories used for storing cache, this way it wouldn't even take a second. The old files could be deleted later partially or whatever.
While in theory it was simple, I'm struggling for a few hours already, just because rename() is throwing me an access denied (code 5)
error. I've already tried almost everything I could, setting the chmod of both parent directory & the directory I want to rename, fixing directory separators, nothing helped.
This is my code:
// $dir = C:xampphtdocstest/cache/posts.cache
$dirToRename = substr($dir, strrpos($dir, '/')+1); // posts.cache
$parentDir = realpath($dir. '/..') . '/'; // C:xampphtdocstest/cache/
error_log('dir '. $dir .' parentDir '. $parentDir .' dirToRename '. $dirToRename);
rename($parentDir . $dirToRename, $parentDir . 'old_'. uniqid() . '_' .$dirToRename);
I tried it many ways, the way the directory separators are different is because after test they are being added by the PHP script, this shouldn't make any difference anyway (and I've tried fixing them without any change)
What I'm getting in the log is:
dir C:xampphtdocstest/cache/posts.cache
parentDir C:xampphtdocstestcache/ dirName posts.cache
PHP Warning:
rename(C:xampphtdocstestcache/posts.cache,C:xampphtdocstestcache/old_5bf72ae342d2f_posts.cache):
Access denied. (code: 5) in C:xampphtdocstestinccache.php on line
308
Obviously, the code is executed at test/inc/cache.php, so it's trying to modify a directory outside of the CWD.
Is this just a XAMPP thing, is there any way to fix this?
EDIT: I thought its about the dot in the directory name, but I can actually rename a directory that I make on my own, but not those that were generated by PHP.
php xampp
|
show 4 more comments
I know there are thousands of questions with similar issue, however most of them got resolved by either using chmod or they just didn't provide the full path for the new name.
I'm trying to change the cache purging behaviour of some website, because when a full purge is done, the website hangs for a good amount of time (it uses a glob & recursive function to delete each file, and there are tens of thousands of them, if not more).
The main idea is to just rename the directories used for storing cache, this way it wouldn't even take a second. The old files could be deleted later partially or whatever.
While in theory it was simple, I'm struggling for a few hours already, just because rename() is throwing me an access denied (code 5)
error. I've already tried almost everything I could, setting the chmod of both parent directory & the directory I want to rename, fixing directory separators, nothing helped.
This is my code:
// $dir = C:xampphtdocstest/cache/posts.cache
$dirToRename = substr($dir, strrpos($dir, '/')+1); // posts.cache
$parentDir = realpath($dir. '/..') . '/'; // C:xampphtdocstest/cache/
error_log('dir '. $dir .' parentDir '. $parentDir .' dirToRename '. $dirToRename);
rename($parentDir . $dirToRename, $parentDir . 'old_'. uniqid() . '_' .$dirToRename);
I tried it many ways, the way the directory separators are different is because after test they are being added by the PHP script, this shouldn't make any difference anyway (and I've tried fixing them without any change)
What I'm getting in the log is:
dir C:xampphtdocstest/cache/posts.cache
parentDir C:xampphtdocstestcache/ dirName posts.cache
PHP Warning:
rename(C:xampphtdocstestcache/posts.cache,C:xampphtdocstestcache/old_5bf72ae342d2f_posts.cache):
Access denied. (code: 5) in C:xampphtdocstestinccache.php on line
308
Obviously, the code is executed at test/inc/cache.php, so it's trying to modify a directory outside of the CWD.
Is this just a XAMPP thing, is there any way to fix this?
EDIT: I thought its about the dot in the directory name, but I can actually rename a directory that I make on my own, but not those that were generated by PHP.
php xampp
Your code does not match your log output. You should always use absolute path names.
– miken32
Nov 22 '18 at 22:34
Probably this path is opened by another process.
– bato3
Nov 22 '18 at 22:35
chmod
does not make any sense on a MS-Windows system. It changes the file system internal permissions, something MS-Windows does not even know.
– arkascha
Nov 22 '18 at 22:39
The output matches, I've tried it now on a simple plain php file and a directory created by me, and it worked fine. I think it's a problem with the permissions that the php script gave to the files/directories when installing, but is it even possible on windows?
– hazelnutek
Nov 22 '18 at 22:41
I also tried changing the cwd & restoring it with getcwd() and chdir(), no luck
– hazelnutek
Nov 22 '18 at 22:46
|
show 4 more comments
I know there are thousands of questions with similar issue, however most of them got resolved by either using chmod or they just didn't provide the full path for the new name.
I'm trying to change the cache purging behaviour of some website, because when a full purge is done, the website hangs for a good amount of time (it uses a glob & recursive function to delete each file, and there are tens of thousands of them, if not more).
The main idea is to just rename the directories used for storing cache, this way it wouldn't even take a second. The old files could be deleted later partially or whatever.
While in theory it was simple, I'm struggling for a few hours already, just because rename() is throwing me an access denied (code 5)
error. I've already tried almost everything I could, setting the chmod of both parent directory & the directory I want to rename, fixing directory separators, nothing helped.
This is my code:
// $dir = C:xampphtdocstest/cache/posts.cache
$dirToRename = substr($dir, strrpos($dir, '/')+1); // posts.cache
$parentDir = realpath($dir. '/..') . '/'; // C:xampphtdocstest/cache/
error_log('dir '. $dir .' parentDir '. $parentDir .' dirToRename '. $dirToRename);
rename($parentDir . $dirToRename, $parentDir . 'old_'. uniqid() . '_' .$dirToRename);
I tried it many ways, the way the directory separators are different is because after test they are being added by the PHP script, this shouldn't make any difference anyway (and I've tried fixing them without any change)
What I'm getting in the log is:
dir C:xampphtdocstest/cache/posts.cache
parentDir C:xampphtdocstestcache/ dirName posts.cache
PHP Warning:
rename(C:xampphtdocstestcache/posts.cache,C:xampphtdocstestcache/old_5bf72ae342d2f_posts.cache):
Access denied. (code: 5) in C:xampphtdocstestinccache.php on line
308
Obviously, the code is executed at test/inc/cache.php, so it's trying to modify a directory outside of the CWD.
Is this just a XAMPP thing, is there any way to fix this?
EDIT: I thought its about the dot in the directory name, but I can actually rename a directory that I make on my own, but not those that were generated by PHP.
php xampp
I know there are thousands of questions with similar issue, however most of them got resolved by either using chmod or they just didn't provide the full path for the new name.
I'm trying to change the cache purging behaviour of some website, because when a full purge is done, the website hangs for a good amount of time (it uses a glob & recursive function to delete each file, and there are tens of thousands of them, if not more).
The main idea is to just rename the directories used for storing cache, this way it wouldn't even take a second. The old files could be deleted later partially or whatever.
While in theory it was simple, I'm struggling for a few hours already, just because rename() is throwing me an access denied (code 5)
error. I've already tried almost everything I could, setting the chmod of both parent directory & the directory I want to rename, fixing directory separators, nothing helped.
This is my code:
// $dir = C:xampphtdocstest/cache/posts.cache
$dirToRename = substr($dir, strrpos($dir, '/')+1); // posts.cache
$parentDir = realpath($dir. '/..') . '/'; // C:xampphtdocstest/cache/
error_log('dir '. $dir .' parentDir '. $parentDir .' dirToRename '. $dirToRename);
rename($parentDir . $dirToRename, $parentDir . 'old_'. uniqid() . '_' .$dirToRename);
I tried it many ways, the way the directory separators are different is because after test they are being added by the PHP script, this shouldn't make any difference anyway (and I've tried fixing them without any change)
What I'm getting in the log is:
dir C:xampphtdocstest/cache/posts.cache
parentDir C:xampphtdocstestcache/ dirName posts.cache
PHP Warning:
rename(C:xampphtdocstestcache/posts.cache,C:xampphtdocstestcache/old_5bf72ae342d2f_posts.cache):
Access denied. (code: 5) in C:xampphtdocstestinccache.php on line
308
Obviously, the code is executed at test/inc/cache.php, so it's trying to modify a directory outside of the CWD.
Is this just a XAMPP thing, is there any way to fix this?
EDIT: I thought its about the dot in the directory name, but I can actually rename a directory that I make on my own, but not those that were generated by PHP.
php xampp
php xampp
edited Nov 22 '18 at 23:28
hazelnutek
asked Nov 22 '18 at 22:29
hazelnutekhazelnutek
207
207
Your code does not match your log output. You should always use absolute path names.
– miken32
Nov 22 '18 at 22:34
Probably this path is opened by another process.
– bato3
Nov 22 '18 at 22:35
chmod
does not make any sense on a MS-Windows system. It changes the file system internal permissions, something MS-Windows does not even know.
– arkascha
Nov 22 '18 at 22:39
The output matches, I've tried it now on a simple plain php file and a directory created by me, and it worked fine. I think it's a problem with the permissions that the php script gave to the files/directories when installing, but is it even possible on windows?
– hazelnutek
Nov 22 '18 at 22:41
I also tried changing the cwd & restoring it with getcwd() and chdir(), no luck
– hazelnutek
Nov 22 '18 at 22:46
|
show 4 more comments
Your code does not match your log output. You should always use absolute path names.
– miken32
Nov 22 '18 at 22:34
Probably this path is opened by another process.
– bato3
Nov 22 '18 at 22:35
chmod
does not make any sense on a MS-Windows system. It changes the file system internal permissions, something MS-Windows does not even know.
– arkascha
Nov 22 '18 at 22:39
The output matches, I've tried it now on a simple plain php file and a directory created by me, and it worked fine. I think it's a problem with the permissions that the php script gave to the files/directories when installing, but is it even possible on windows?
– hazelnutek
Nov 22 '18 at 22:41
I also tried changing the cwd & restoring it with getcwd() and chdir(), no luck
– hazelnutek
Nov 22 '18 at 22:46
Your code does not match your log output. You should always use absolute path names.
– miken32
Nov 22 '18 at 22:34
Your code does not match your log output. You should always use absolute path names.
– miken32
Nov 22 '18 at 22:34
Probably this path is opened by another process.
– bato3
Nov 22 '18 at 22:35
Probably this path is opened by another process.
– bato3
Nov 22 '18 at 22:35
chmod
does not make any sense on a MS-Windows system. It changes the file system internal permissions, something MS-Windows does not even know.– arkascha
Nov 22 '18 at 22:39
chmod
does not make any sense on a MS-Windows system. It changes the file system internal permissions, something MS-Windows does not even know.– arkascha
Nov 22 '18 at 22:39
The output matches, I've tried it now on a simple plain php file and a directory created by me, and it worked fine. I think it's a problem with the permissions that the php script gave to the files/directories when installing, but is it even possible on windows?
– hazelnutek
Nov 22 '18 at 22:41
The output matches, I've tried it now on a simple plain php file and a directory created by me, and it worked fine. I think it's a problem with the permissions that the php script gave to the files/directories when installing, but is it even possible on windows?
– hazelnutek
Nov 22 '18 at 22:41
I also tried changing the cwd & restoring it with getcwd() and chdir(), no luck
– hazelnutek
Nov 22 '18 at 22:46
I also tried changing the cwd & restoring it with getcwd() and chdir(), no luck
– hazelnutek
Nov 22 '18 at 22:46
|
show 4 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438663%2fphp-rename-directory-acces-denied-on-windows-xampp-despite-correct-chmod-f%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438663%2fphp-rename-directory-acces-denied-on-windows-xampp-despite-correct-chmod-f%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your code does not match your log output. You should always use absolute path names.
– miken32
Nov 22 '18 at 22:34
Probably this path is opened by another process.
– bato3
Nov 22 '18 at 22:35
chmod
does not make any sense on a MS-Windows system. It changes the file system internal permissions, something MS-Windows does not even know.– arkascha
Nov 22 '18 at 22:39
The output matches, I've tried it now on a simple plain php file and a directory created by me, and it worked fine. I think it's a problem with the permissions that the php script gave to the files/directories when installing, but is it even possible on windows?
– hazelnutek
Nov 22 '18 at 22:41
I also tried changing the cwd & restoring it with getcwd() and chdir(), no luck
– hazelnutek
Nov 22 '18 at 22:46