• Archives

  • File upload in php

    By admin | December 1, 2007

    If you want users to upload files you can do this by using php

    HTML FILE

    <form action=”upload.php” method=”post”
    enctype=”multipart/form-data”>
    <input type=”file” name=”upload” />
    <br />
    <input type=”submit” name=”submit” value=”Submit” />
    </form>

    The file of yours will now consist of a browse button through which a user can select the file he wants to upload

    The upload.php will display the file information and upload the file to the folder upload

    UPLOAD.PHP

    <?php
    if(isset($_FILES[‘upload’])){if ($_FILES[“file”][“error”] > 0)
    {
    echo “Contain error ” . $_FILES[“file”][“error”] . “<br />”;
    }
    else
    {
    echo “File name ” . $_FILES[“file”][“name”] . “<br />”;
    echo “File Type: ” . $_FILES[“file”][“type”] . “<br />”;
    echo “File 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 ‘where have you come from ha’;
    }?>
    
    

    Create both the files and upload to the server then create a folder named upload [important] Or else you will get error.

    When done check

    Thanks
    krates

    Topics: PHP | 2 Comments »

    Related Links: