rename & parse error

Discussion in 'PHP' started by promotingspace.net, Aug 20, 2007.

  1. #1
    Hi
    I'm trying to rename images and get parse errors. the main isea can be found in the code below:
    <?php
    $name='m08';
    $name=md5($name);
    $newname=$name.gif;
    echo $newname;
    rename(uploads/m08.gif,uploads/$newname);
    ?>
    PHP:
    how should the code be to work?
     
    promotingspace.net, Aug 20, 2007 IP
  2. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You're leaving off a bunch of necessary quotes from your string constants.

    
    <?php
    $name='m08';
    $name=md5($name);
    $newname=$name . '.gif';
    echo $newname;
    rename('uploads/m08.gif','uploads/'.$newname);
    ?>
    
    PHP:
     
    sea otter, Aug 20, 2007 IP
  3. promotingspace.net

    promotingspace.net Peon

    Messages:
    361
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks.
    how about this one:
    
    <?
     move_uploaded_file($_FILES["file"]["tmp_name"],
          "uploads/" . $_FILES["file"]["name"]);
          $newname=md5(time());
          rename('uploads/'. $_FILES["file"]["name"]','uploads/'.'$newname);
          echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
    ?>
    
    PHP:
     
    promotingspace.net, Aug 20, 2007 IP
  4. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The line with rename has a syntax error. Remove the single quote from the last parameter '$newname so that it is just $newname.

    You can check the syntax of a script without actually running it by calling the following from the command line:

    
    php -l script_name.php
    
    Code (markup):
    Note that the parameter is lower-case "el", not the number one.
     
    sea otter, Aug 20, 2007 IP
  5. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #5
    That was half the problem, there was also a single quote after $_FILES['...'] that shouldn't have been there.

    rename('uploads/' . $_FILES["file"]["name"], 'uploads/' . $newname);
    PHP:
     
    krt, Aug 21, 2007 IP
  6. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yup, missed that one. Didn't even listen to my own advice:D
     
    sea otter, Aug 21, 2007 IP