Title: [function.rename]: Access is denied. (code: 5)
Last modified: August 20, 2016

---

# [function.rename]: Access is denied. (code: 5)

 *  [yeagerc50](https://wordpress.org/support/users/yeagerc50/)
 * (@yeagerc50)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/functionrename-access-is-denied-code-5/)
 * I have successfully created a directory inside wordpress using the following:
   
   $tempDir = ABSPATH . ‘wp-content’ . DIRECTORY_SEPARATOR . ‘themes’ . DIRECTORY_SEPARATOR.‘
   used-car-lot-theme’; mkdir($tempDir,0700); however, when i try to use rename:
   rename(ABSPATH.’wp-content’.DIRECTORY_SEPARATOR.’plugins’.DIRECTORY_SEPARATOR.’
   used-car-lot’.DIRECTORY_SEPARATOR.’twentyten1′, ABSPATH . ‘wp-content’ . DIRECTORY_SEPARATOR.‘
   themes’ . DIRECTORY_SEPARATOR . ‘used-car-lot-theme’); I get the subject error
   message: [function.rename]: Access is denied. (code: 5)
 * I’m fairly certain it’s a Windows thing but after a day of searching for answers
   I have no clue how to attack
    the problem.
 * Any help would be greatly appreciated.

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/functionrename-access-is-denied-code-5/#post-3252421)
 * PHP version? rename() only works on windows as of version 5.3.1 .
 *  Thread Starter [yeagerc50](https://wordpress.org/support/users/yeagerc50/)
 * (@yeagerc50)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/functionrename-access-is-denied-code-5/#post-3252422)
 * PHP version is 5.3.8
 * Additional information:
    both folder permissions are 0777, I tried including 
   it in the register_activation function of the plugin (of course) as well as adding
   it as a separate action but that didn’t work either.
 * Would this somehow require an nonce?
 *  Thread Starter [yeagerc50](https://wordpress.org/support/users/yeagerc50/)
 * (@yeagerc50)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/functionrename-access-is-denied-code-5/#post-3252424)
 * From error log:
 * [08-Dec-2012 19:42:53] PHP Warning: rename(C:\xampp\htdocs\wordpress/wp-content/
   plugins/used-car-lot/twentyten1,C:\xampp\htdocs\wordpress/wp-content/themes/used-
   car-lot-theme) [[function.rename](https://wordpress.org/support/topic/functionrename-access-is-denied-code-5/function.rename?output_format=md)]:
   Access is denied. (code: 5) in C:\xampp\htdocs\wordpress\wp-content\plugins\used-
   car-lot\wp.display_cars1.php on line 76
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/functionrename-access-is-denied-code-5/#post-3252444)
 * PHP doesn’t care if you use a nonce or not, but you should use one to assure 
   that the request is coming from the form you sent and not from a bad actor who
   figured out how to craft a request that would do something bad to your file structure.
 * I know problems with rename in windows have occurred for many. Have you reviewed
   the comments on [http://php.net/manual/en/function.rename.php](http://php.net/manual/en/function.rename.php)?
   May something there will sound a lot like your problem?
 *  Thread Starter [yeagerc50](https://wordpress.org/support/users/yeagerc50/)
 * (@yeagerc50)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/functionrename-access-is-denied-code-5/#post-3252448)
 * Yes, I’ve review the page you’ve referenced but instead of doing it what I want
   with a script, I figure I’ll just have the user install template files via a 
   full fledged template or a child theme in addition to the plugin.
 * unless….
 * Is it possible to run custom template files from the plugin folder? I always 
   assumed that templates MUST be in the theme folder in order for pages to recognize
   the template.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/functionrename-access-is-denied-code-5/#post-3252452)
 * Depends on how the template is invoked. Generally, it does need to be in the 
   theme folder so WP can find it when it’s trying to find the right template based
   on the client request.
 * But if you’re explicitly loading a particular file as part of some special functionality
   that is independent of the request parser, it can reside anywhere that is accessible
   to the client.
 * BTW, I would think the rename would work if you were to explicitly unlink all
   the files in the target, then remove the now empty directory. (A more painful
   routine to implement for sure) I believe windows is balking with your rename 
   because the folder already exists. But then, I’m guessing at the context of your
   issue, so maybe I’ve mis-guessed entirely.
 *  [selnomeria](https://wordpress.org/support/users/selnomeria/)
 * (@selnomeria)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/functionrename-access-is-denied-code-5/#post-3252470)
 * I think you are trying to touch the hidden files. in such case, you may use this
   to avoid hidden files: if (substr(“$filename”, 0, 1) != “.”) { your action }

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘[function.rename]: Access is denied. (code: 5)’ is closed to new replies.

## Tags

 * [rename](https://wordpress.org/support/topic-tag/rename/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 7 replies
 * 3 participants
 * Last reply from: [selnomeria](https://wordpress.org/support/users/selnomeria/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/functionrename-access-is-denied-code-5/#post-3252470)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
