• Archives

  • AddThis Social Bookmark Button

    Add to Technorati Favorites

  • Upcoming Conferences

    • no upcoming events
  • File upload in php

    By krates | 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

    Share and Enjoy:
    • Digg
    • del.icio.us
    • Facebook
    • NewsVine
    • Reddit
    • StumbleUpon
    • YahooMyWeb
    • Google Bookmarks
    • Yahoo! Buzz
    • TwitThis
    • Live
    • LinkedIn
    • Pownce
    • MySpace

    Topics: PHP | 2 Comments »

    Related Links:

    2 Responses to “File upload in php”

    1. Nancy Odell Says:
      December 1st, 2007 at 3:39 am

      Hi…. i was searching for sing down the moon by scott o dell and i came across your post and it is definitely the most sensible thing i have seen in a long time, and in my opinion you got something good going here, i have to get my friends to subscribe to your post about nnial 2007 – salvatore iaconesi – del.icio.us poetry.

    2. live7n Says:
      December 4th, 2007 at 11:38 pm

      Good informative for new site designer.