Help - Where is the parse error in this PHP photo upload script

Discussion in 'PHP' started by ketting00, Sep 13, 2009.

  1. #1
    Hi, I have problem with the upload script.

    I have to files here:

    1. upload.php

    <form name="uploadphoto" action="upload_file.php" method="post" enctype="multipart/form-data">
    <label for="file">Filename:</label>
    <input type="file" name="photofile" id="photofile" />
    <br />
    <input type="submit" name="submit" value="Submit" />
    </form>


    2. upload_file.php

    <?php
    session_start();

    if ((($_FILES["photofile"]["type"] == "image/gif")
    || ($_FILES["photofile"]["type"] == "image/jpeg")
    || ($_FILES["photofile"]["type"] == "image/pjpeg"))
    && ($_FILES["photofile"]["size"] < 20000))
    {
    if ($_FILES["photofile"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["photofile"]["error"] . "<br />";
    }
    else
    {
    echo "Upload: " . $_FILES["photofile"]["name"] . "<br />";
    echo "Type: " . $_FILES["photofile"]["type"] . "<br />";
    echo "Size: " . ($_FILES["photofile"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["photofile"]["tmp_name"] . "<br />";

    if (file_exists("../photos/" . $_FILES["photofile"]["name"]))
    {
    echo $_FILES["photofile"]["name"] . " already exists. ";
    }
    else
    {
    move_uploaded_file($_FILES["photofile"]["tmp_name"],
    "../photos/" . $_SESSION['photos'] . $_FILES["photofile"]["name"],

    chmod(("../photos/" . $_SESSION['photos'] . ".jpg"), 0777);
    header('Location: home.php');
    }
    }
    }
    else
    {
    echo "Invalid file";
    }

    ?>


    The compiler said: "Parse error: parse error in C:\wamp\www\project\upload_file.php on line 27"

    I did copy codes from a textbook, except i changed $_FILES["photofile"] for $_FILES["file"].

    Please help and thanks inadvance.
     
    ketting00, Sep 13, 2009 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    try

    
    
    move_uploaded_file($_FILES["photofile"]["tmp_name"],
    "../photos/" . $_SESSION['photos'] . $_FILES["photofile"]["name"]);
    
    
    PHP:
     
    stephan2307, Sep 13, 2009 IP
  3. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #3
    This line isn't correct....

    move_uploaded_file($_FILES["photofile"]["tmp_name"],
    "../photos/" . $_SESSION['photos'] . $_FILES["photofile"]["name"]);
    PHP:
     
    shallowink, Sep 13, 2009 IP
  4. ketting00

    ketting00 Well-Known Member

    Messages:
    782
    Likes Received:
    28
    Best Answers:
    3
    Trophy Points:
    128
    #4
    Thanks for reply swiftly. It solves the problem.
     
    ketting00, Sep 13, 2009 IP