1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

website upload

Discussion in 'Programming & Webmastering' started by binsky3333, Aug 8, 2008.

  1. binsky3333

    binsky3333 New Member

    Joined:
    Jul 5, 2007
    Messages:
    643 (0.18/day)
    Thanks Received:
    21
    Hi,
    I am trying to make a website upload page, but i cant.
    Here is my Form:

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


    And here is my upload.php:

    <?php
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/pjpeg"))
    && ($_FILES["file"]["size"] < 20000))
    {
    if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
    else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"]))
    {
    echo $_FILES["file"]["name"] . " already exists. ";
    }
    else
    {
    move_uploaded_file($_FILES["file"]["tmp_name"],
    "upload/" . $_FILES["file"]["name"]);
    echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
    }
    }
    }
    else
    {
    echo "Invalid file";
    }
    ?>


    Basically im using http://w3schools.com/php/php_file_upload.asp
    But whenever i try and upload something i get "invalid file"
    BTW I AM USING XAMPP FOR TESTING!
    Can anyone figure out whats wrong?
     
  2. W1zzard

    W1zzard Administrator Staff Member

    Joined:
    May 14, 2004
    Messages:
    16,644 (3.47/day)
    Thanks Received:
    17,228
    var_dump($_FILES);
    to see whats the input data you get fed
     
    10 Year Member at TPU
  3. binsky3333

    binsky3333 New Member

    Joined:
    Jul 5, 2007
    Messages:
    643 (0.18/day)
    Thanks Received:
    21
    I am not good with php! So what do you mean by that?
     
  4. Jizzler

    Jizzler

    Joined:
    Aug 10, 2007
    Messages:
    4,002 (1.11/day)
    Thanks Received:
    1,041
    Location:
    Geneva, FL, USA
    echo "Invalid file"; is going to happen if the file is not a gif or jpeg, or if it's over 20KB.

    Putting var_dump($_FILES); at the start of the script (after the opening <?php tag) shows you the content of the $_FILES array, and thus the file type and size of the file you're trying to upload.
     
    Crunching for Team TPU
  5. binsky3333

    binsky3333 New Member

    Joined:
    Jul 5, 2007
    Messages:
    643 (0.18/day)
    Thanks Received:
    21
    oh ok, thanks!
     

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)