rename('/images/old_name.jpg', '/images/new_name.jpg');
This code gives file not found.
Script, where files are called is placed inside /source/ folder.
Files can be opened from http://site.com/images/old_name.jpg
How开发者_JAVA技巧 to get these files from root?
rename is a filesystem function and requires filesystem paths. But it seems that you’re using URI paths.
You can use $_SERVER['DOCUMENT_ROOT'] to prepend the path to the document root:
rename($_SERVER['DOCUMENT_ROOT'].'/images/old_name.jpg', $_SERVER['DOCUMENT_ROOT'].'/images/new_name.jpg');
Or for more flexibility, use dirname on the path to the current file __FILE__:
rename(dirname(__FILE__).'/images/old_name.jpg', dirname(__FILE__).'/images/new_name.jpg');
Or use relative paths. As you’re in the /script folder, .. walks one directory level up:
rename('../images/old_name.jpg', '../images/new_name.jpg');
In PHP the root (/) is the root of the filesystem not the "webroot". If the php-file is in the /source/ directory and images are in /source/images/ then this will work:
rename('images/old_name.jpg', 'images/new_name.jpg');
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论