1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

PHP rename not working

Discussion in 'Web Design & Development' started by DrP, Jul 28, 2006.

Thread Status:
Not open for further replies.
Advertisement
  1. DrP

    DrP Thread Starter

    Joined:
    Jul 23, 2005
    Messages:
    739
    I am trying to rename a variable on the third line, below:

    $testname1 = $newfilename;
    $testname2 = $ImageName;
    rename($ImageName, $newfilename);
    $testname3 = $ImageName;

    However, it isn't happening! To test it I am doing this:

    <?php echo $testname1 ?>
    <br />
    <?php echo $testname2 ?>
    <br />
    <?php echo $testname3 ?>

    If it was working then $testname 3 should be tha same as $testname1.
    But it isn't! It's the same as $testname2, which means it hasn't been renamed!
    What is going on? What have I not done here? I've spent ages looking at this and as far as I can see my code is fine.
    Please...
     
  2. covert215

    covert215 Banned

    Joined:
    Apr 22, 2006
    Messages:
    2,595
    Lets trace your logic using numbers instead of variables. Say $newfilename is 1 and $ImageName is 2.

    $testname1 is assigned the value of 1.
    $testname2 is assigned the value of 2.
    $ImageName is renamed as $newfilename, which duplicates the variable $ImageName and makes $newfilename equal to 2.
    $testname3 is assigned the value of 2.

    It worked properly.
     
  3. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    rename() does not change the value of any variable, it only renames the file.
     
  4. DrP

    DrP Thread Starter

    Joined:
    Jul 23, 2005
    Messages:
    739
    Thanks for that. I'd been trying to follow a book and it was obviously getting late. That and the fact the book is so poorly written.
    Covert215: Even though we now know rename doesn't change the value of variables, if it did, where'd you get the duplicate from, anyway?
    Thanks again,
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/487361

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice