Results 1 to 2 of 2

Thread: Image upload

  1. #1
    Join Date
    Jan 2010
    Posts
    3,641
    Tokens
    138

    Latest Awards:

    Default Image upload

    I've only tired php once and i gave up but i really want to learn it so i'm starting off with a project involving php.

    Image upload website.

    I got this code off w3schools but it doesn't work, I know i shouldn't just copy and paste the code but if someone would explain/tell me the problem with the code it would help.

    Remember i know nothing about php so don't say 'you need to do this' because i won't know how to do that.

    REP+ for replies

    Here is the code:

    Index.html:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


    <html>


    <head>
    <title> Scrni.com - Image sharing made simple.</title>
    </head>


    <body>
    <form action="upload_image.php" method="POST" enctpye="multipart/form-data">
    <input type="file" name="browse" id="file"/><br/>
    <input type="file" name="browse" id="file"/><br/>
    <input type="file" name="browse" id="file"/><br/>
    <input type="file" name="browse" id="file"/><br/>
    <input type="file" name="browse" id="file"/><br/>
    <input type="submit" name="submit" value="Upload"/>

    </body>


    </html>

    upload_image.php:

    <?php
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/pjpeg")
    || ($_FILES["file"]["type"] == "image/png"))
    && ($_FILES["file"]["size"] < 10000000))
    {
    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";
    }
    ?>
    Last edited by Thomas; 19-11-2011 at 03:35 PM.

  2. #2
    Join Date
    Jan 2010
    Posts
    3,641
    Tokens
    138

    Latest Awards:

    Default

    nvm now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •