Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

php rename file error

Posted on 2010-08-15
4
Medium Priority
?
632 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

604 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