Solved

php rename file error

Posted on 2010-08-15
4
626 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:Solutionabc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Frozenice
ID: 33441993
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
}
0
 
LVL 4

Expert Comment

by:Frozenice
ID: 33441996
followup.

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






br
0
 

Author Comment

by:Solutionabc
ID: 33442063
I have put in the absolute path and it still doesn't work.
0
 

Accepted Solution

by:
Solutionabc earned 0 total points
ID: 33442335
this is what worked for me


rename("instrumentals/".$newInstrumental,"instrumentals/".$finalInstrumental);

Open in new window

0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question