Ibrahim Ibrahim
Ibrahim Ibrahim

Reputation: 9

Rename function don't work with folders in php

This is my PHP code

<?php
rename(realpath(dirname(__FILE__)) . '/old', realpath(dirname(__FILE__)) . '/new');
?>

And I getting this error

Warning: rename(C:\xampp\htdocs\goahead\php\old, C:\xampp\htdocs\goahead\php/new): Access is denied (code: 5) in C:\xampp\htdocs\goahead\php\test.php on line 3

What is the problem?

Upvotes: 0

Views: 780

Answers (1)

Omar Khaled
Omar Khaled

Reputation: 66

The problem is php file doesn't have access to rename files make sure you run the web server as administrator (windows)

For Linux you will type this code in terminal

chmod 777 php_file.php

  • EDIT *

If all of this doesn't work then go to properties in the file that need to be renamed then go to tab security and make sure that everyone user is added and can edit the file (windows)

In Linux you should check file owner and change it

Upvotes: 1

Related Questions