Reading a file in PHP



File Handling in PHP




PHP has many built-in (ready made) functions for handling files.
we can open files from URL (Web) also.


Q1)Accept a file name from user and display the content.




<?php
if (isset($_POST['f1']))
  {
   $file=$_POST['f1'];


   if ( ! (file_exists( $file ) ) ) 
         {
             echo "$file does not exist<br/>";
            
         }


   $data = file_get_contents( $file);
   echo $data;


 }
?>
 <html>
 <body><form method=post>
 <input type=file name="f1"><input type=submit value=read>
 </form>
</body>
</html>

1 comment:

Thanks for visiting my Blog!

Have a Question ? Need Help in College Assignments, Need Code that is not available here? Just leave a comment & get your code instantly.

Tips to Enhance Your Blog