Solved

php rename file error

Posted on 2010-08-15
4
622 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
  • 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php checkbox validation 5 27
write screen output to text file 21 47
Attach to file (img) a unique id 8 27
Php recording post 4 49
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

809 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