Reputation: 4982
Can anyone tell how to change a filename of a file which is a located in a folder using PHP?
rename("http://localhost/DXXX/photos/".$photoNamepart, "http://localhost/DXXX/photos/".$phototmpNamepart);
Error:Message: rename() [function.rename]: http wrapper does not support renaming
Upvotes: 1
Views: 6119
Reputation: 57
rename($_SERVER['DOCUMENT_ROOT'].'/dir1/abc.png', $_SERVER['DOCUMENT_ROOT'].'/dir2/abc.png')
Above code works for me on CI
Upvotes: 1
Reputation: 45
This will works properly copy(getcwd()."/tmp/tmp_file.txt", getcwd()."/tmp/my_file.txt");
Upvotes: 0
Reputation: 1635
You're using rename wrong here. fopen
, file_get_contents
work fine with URLs - but that's more out of convenience rather than correctness.
For the code that you've written - you first need the absolute path of the file that you want to rename. It will work only on the local machine and on files that your webserver is configured to have write-access on.
Let's say your web server root is WEB_ROOT
,
rename(WEB_ROOT."/DXXX/photos/".$photoNamePart, WEB_ROOT."/DXXX/photos/".$photoTempNamePart;
should do the trick.
Upvotes: 1
Reputation: 1765
shell_exec('mv former_filename new_filename');
you should be having appropriate permissions to do this
Upvotes: 0