简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM