Solved

php rename file error

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now