Search This Blog

read a file in php

<?php

if(isset($_POST['filename']))
{
  if(!empty($_POST['filename']))
  {
    $file=$_POST['filename'].'.txt';
    if(file_exists($file))
    {
         $filename = fopen("$file", "r") ;
         while(!feof($filename))
               {
                 echo fgets($filename)."<br>";
               }
         fclose($filename);
    }
    else
    echo 'file not exits';
  }
 else
echo 'empty';

}
?>

<form action="file-read.php" method="POST">
<input type="text" name="filename">
.txt
<input type="submit" value="submit">
</form>

output :
1)enter the file name for read that file
2)that file must be text file

ex :        test.txt

Share Links

Related Posts Plugin for WordPress, Blogger...