• Upload files in PHP using a simple HTML form

    For uploading file into php you have to go through the following steps which are described below.
    Step 1 : First you have to create a form into php file which i have
    described below.
    Step 2 : Now copy below php code and put it into that php file.
    Step 3 : Now you have to create folder where you have to put your uploaded files. i named that folder “upload”.
    Step 4 : Now give that folder path where you have to stored your files.

    i had stored it in $target variable.

    code :

    (html part)

    Please choose a file:

    (php part)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    
    <!--?php 
    $target = "upload/";
    $target = $target . basename( $_FILES['uploaded']['name']) ;
    $ok=1;
     
    //This is our size condition
    if ($uploaded_size --> 350000)
    {
    echo "Your file is too large.
    ";
    $ok=0;
    }
     
    //This is our limit file type condition
    if ($uploaded_type =="text/php")
    {
    echo "No PHP files
    ";
    $ok=0;
    }
     
    //Here we check that $ok was not set to 0 by an error
    if ($ok==0)
    {
    Echo "Sorry your file was not uploaded";
    }
     
    //If everything is ok we try to upload it
    else
    {
    if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
    {
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been
     
    uploaded";
    }
    else
    {
    echo "Sorry, there was a problem uploading your file.";
    }
    }
    ?&gt;

Comments on this post

Leave a Reply

  • Security Code :


    9 + three =