Very, very simple PHP script - Full of probs!

Discussion in 'PHP' started by RogerWilco, Feb 20, 2009.

  1. #1
    I have a very simple PHP script that is is to upload single file...

    <?php
    try{ 
    $uploaddir = $_GET['dir'];
    $uploadfile = $uploaddir . basename($_FILES["file"]["name"]);
    move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile);
    echo "Success: " . $_FILES["file"]["name"] . ";
    }catch (Exception $e){
    echo 'Boo Boo!: '.$e->getMessage();
    }
    ?>
    PHP:
    The error is on the second last line 'syntax error, unexpected T_STRING, expecting ',' or ';'...

    If I don't echo back the error message, but a simple 'Hello', I get a $end error instead. I have no idea why and I also have no real idea about PHP...

    If the Try Catch block is removed, it works fine. I am using PHP5.

    Any ideas?
     
    RogerWilco, Feb 20, 2009 IP
  2. Spawny

    Spawny Well-Known Member

    Messages:
    252
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    110
    #2
    try replacing
    echo 'Boo Boo!: '.$e->getMessage();
    PHP:
    with

    echo "Boo Boo!:".$e->getMessage();
    PHP:
     
    Spawny, Feb 20, 2009 IP
  3. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Replace
    echo "Success: " . $_FILES["file"]["name"] . ";
    PHP:
    with
    echo "Success: " . $_FILES["file"]["name"];
    PHP:
    - ads2help
     
    ads2help, Feb 20, 2009 IP
  4. RogerWilco

    RogerWilco Peon

    Messages:
    140
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks fellows - fixed it!
     
    RogerWilco, Feb 20, 2009 IP