Site icon Tutorial

Opening a file in PHP

Opening a file in PHP

In PHP, you can open a file using the fopen() function, which takes two parameters: the first parameter is the file name or path, and the second parameter specifies the mode in which the file should be opened.

The mode parameter can be a combination of the following:

Here’s an example of opening a file in PHP:

$file = fopen(“example.txt”, “r”); // do something with the file… fclose($file);

In this example, the fopen() function opens the file “example.txt” in read-only mode and returns a file handle, which is stored in the $file variable. Once you’re done working with the file, you should close it using the fclose() function to free up resources.

Apply for PHP Certification!

https://www.vskills.in/certification/certified-php-developer

Back to Tutorials

Exit mobile version