Loading...
PHP

multipart/form_data

It is a common MIME tag can upload any type of file.

  1. is_upload_file: 
    By using this function we can check whether file is uploaded from browser temporary memory location to permanent memory.
  2. move_uploaded_file:
    move is to uploaded file form temporary memory location to permanent memory location arguments are temporary memory location file name and permanent location.
    Example:
    <form method=”post” action=” upload.php” enctype=”multipart/form_data”>
    select file:<input type=”file” name= “f1″> <br>
    <input type=”submit” name=”sub” vale=”upload”>
    </fprm>
    <?php
    //print_r($_FILES);
    if (isset($_POST[‘sub’])){
    $fname= $_FILES[‘f1’][‘name’];
    if(move_upload_file($_FILE[‘f1’][‘tmp_name’], “uploads/$fname”))
    {
    echo “moved”;
    echo ‘<img src=”uploads/’.$fname.'” width=”100″ height=”100″/>’;
    }
    else
    {
    echo “Not moved”;
    }}
    ?>
  3. Not to move .exefile:
    <?php
    $type=$_FILE[‘f1’][‘type’];
    if($type==”application/octet_stream”)
    echo “Exe not allowed”;
    else
    {
    $fname=$_FILES[‘f1’][‘name’];
    if(move_uploaded_file($_FILES[‘f1’][‘tmp_name’],”uploads/$fname”))
    echo “moved”
    else
    echo “Not moved”;
    ?>
Leave a Reply

Your email address will not be published. Required fields are marked *