Upload image

Discussion in 'PHP' started by davenet, Apr 4, 2007.

  1. #1
    Hi,

    I have the following code:

    browse.php

    <html>
    <head>
    <title>Form Upload</title>
    </head>
    <body>
    <?
    echo "<form method=\"post\" action=\"upload.php\" ENCTYPE=\"MULTIPART/FORM-DATA\">";
    echo "<table>

    <tr>
    <td>Foto</td>

    <td><input type=\"FILE\" name=\"foto\">
    </td>
    </tr>
    <tr>
    <td><input type=\"submit\" value=\"upload\">
    <input type=\"reset\" value=\"reset\">
    </td>
    </tr>

    </table></form>";
    ?>
    </body>
    </html>

    After I press upload button, it will take me to the following code:

    upload.php

    <html>
    <head><title>Upload File</title></head>
    <body>
    <?
    echo "Ini adalah atribut \$foto = $foto";
    echo "<br>";
    echo "Ini adalah atribut \$foto_name = $foto_name";
    echo "<br>";
    echo "Ini adalah atribut \$foto_size = $foto_size";
    echo "<br>";
    echo "Ini adalah atribut \$foto_type = $foto_type";
    copy ($foto, "../image/$foto_name");
    ?>
    </body>
    </html>

    I expect it show me a page with no blanks, instead it gives the following:

    Ini adalah atribut $foto =
    Ini adalah atribut $foto_name =
    Ini adalah atribut $foto_size =
    Ini adalah atribut $foto_type =


    What should I add to the codes so that I have all the blanks filled-in?
     
    davenet, Apr 4, 2007 IP
  2. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #2
    Well for a start you are using register globals which is very bad. You should use the proper variables i.e:
    $_FILES['foto']['name'];
    $_FILES['foto']['size'];
    $_FILES['foto']['type'];
    $_FILES['foto']['tmp_name'];
     
    papa_face, Apr 4, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    EDIT:
    A few seconds too slow on the submit button...

    Use $_FILES['foto'] instead. Or do just:

    
    
    print_r($_FILES);
    
    PHP:
     
    nico_swd, Apr 4, 2007 IP