Solutionabc
asked on
php rename file error
Hi,
I am trying to rename a file located in a directory but I keep getting the following error.
Warning: rename(/instrumentals/test Song.mp3,/ instrument als/30test Song.mp3) [function.rename]: No such file or directory
The instrumentals folder is in the same location as the script with the rename function. The code I am using is as follows.
Thanks for your help.
I am trying to rename a file located in a directory but I keep getting the following error.
Warning: rename(/instrumentals/test
The instrumentals folder is in the same location as the script with the rename function. The code I am using is as follows.
Thanks for your help.
rename("/instrumentals/".$newInstrumental,"/instrumentals/".$finalInstrumental);
followup.
you need to give RENAME command the absolute path of the file directory.
br
you need to give RENAME command the absolute path of the file directory.
br
ASKER
I have put in the absolute path and it still doesn't work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$filename = '/path/to/foo.txt';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
renaming..
$filename = '/path/to/foo.txt';
if (file_exists($filename)) {
rename ("/folder/file.ext", "/folder/newfile.ext");
} else {
echo "The file $filename does not exist";
}
or...
if( file_exists( $_SERVER{'DOCUMENT_ROOT'} . "/folder/file.ext")) {
rename ($_SERVER{'DOCUMENT_ROOT."
br
}