How to use fopen in PHP

In this article I will go to explain about fopen function in PHP.
  • 2493

PHP fopen() function

The PHP fopen() is used to open a file in PHP to performing read, write, or rewrite operations.

Syntax of fopen function

fopen("filename","mode");


Parameters in fopen function

It have two parameters.

  • filename

    The file name, whose want to open you.

  • mode

    Modes are following types:

  1. r-

    It is used for reading a file from beginning.
     

  2. r+

    It is used for reading and writing a file from beginning.
     

  3. w-

    It is used for writing a file from beginning.
     

  4. w+

    It is used for writing and  reading a file from beginning.
     

  5. a-

    It is used for writing a file from end.

Example of fopen function

<html>

<body>

 

<?php

$file=fopen("sharad.txt","r-") or exit("Unable to open file!");

?>

 

</body>

</html>


You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.