Link to home
Start Free TrialLog in
Avatar of Solutionabc
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/testSong.mp3,/instrumentals/30testSong.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.
rename("/instrumentals/".$newInstrumental,"/instrumentals/".$finalInstrumental);

Open in new window

Avatar of Frozenice
Frozenice
Flag of Philippines image

because, you need to point the code to the right path/dir


$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."/folder/file.ext", $_SERVER{'DOCUMENT_ROOT."/folder/newfile.ext");




br
}
followup.

you need to give RENAME command the absolute path of the file directory.






br
Avatar of Solutionabc
Solutionabc

ASKER

I have put in the absolute path and it still doesn't work.
ASKER CERTIFIED SOLUTION
Avatar of Solutionabc
Solutionabc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial