*****PHP Renaming Else Help*****

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zylkaa
Forum Newbie
Posts: 8
Joined: Mon Mar 23, 2009 7:32 pm
Location: Places

*****PHP Renaming Else Help*****

Post by zylkaa »

So, I have my code for renaming files on my server, since I run a small file company called File Fetchers. Unfortunately, my PHP code isn't up to snuff, and I was wondering whether you could help me with it.

Code for rename.html:

Code: Select all

<form method="POST" action="rename.php">
Original File Name: &nbsp <input name="oldfile">
<br>
New File Name: &nbsp <input name="newfile">
<br>
<input type="submit">
</form>
Code for rename.php

Code: Select all

<?php
  $file_old= $_REQUEST['oldfile'] ;
  $file_new = $_REQUEST['newfile'] ;
 
if(!rename($file_old, $file_new))
{
echo ("Your file was not renamed."); 
}
?>

I know that the echo should say Renaming Successful, but this code thinks the echo is the else, and vice versa.
I feel like a "noob", but how do I add an else? I tried this, but kept getting T_ELSE errors.

Thanks,
Alex
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: *****PHP Renaming Else Help*****

Post by requinix »

Code: Select all

if(!rename($file_old, $file_new))
{
echo ("Your file was not renamed.");
}
else
{
echo ("Rename successful.");
}
Consider flipping them around (first comes the good news, second comes the bad news).

What did you try that didn't work?
zylkaa
Forum Newbie
Posts: 8
Joined: Mon Mar 23, 2009 7:32 pm
Location: Places

Re: *****PHP Renaming Else Help*****

Post by zylkaa »

Thanks a lot! It worked perfectly!

Alex
Post Reply