Not like any other post variables, file element information is posted as two dimensional array. So, getting post data for a file element can be accomplished as below.

<?php
  if(isset($_POST['btnUpload'])){
    $name = $_FILES['upfile']['name'];
    $tmpname = $_FILES['upfile']['tmp_name'];
    $sizer = $_FILES['upfile']['size'];
    
    // open file to read data;    
    $fp = fopen($tmpname, 'r'); 
    // You can do whatever you need to from this point.
    // The example below reads the contents of uploaded text file.
    $content = fread($fp, filesize($tmpname));
    fclose($fp);
    // break data from csv into array line by line
    $data = preg_split('/\r\n|\r|\n/', $content); 
?>

<FORM action="<?=$_SERVER['PHP_SELF']=>"  method="post" enctype="multipart/form-data">
<input name="upfile" id="upfile" type="file">
<input value="Upload" name="btnUpload" id="btnUpload" type="submit">
</FORM>

Leave a Reply

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