File Editor Using PHP

In this tutorial we will show you how to open, edit and delete file using PHP and HTML. File handling is an important part of any web application. You often need to open and process a file for different tasks. PHP Manipulating Files. PHP has several functions for creating, reading, uploading, and editing files

This chapter will explain following functions related to file

1. Choose which file to open
2. Read the contents of a file
3. Save content to file


  • List files and directories inside the specified path

Displaying files and directory present inside any directory by using scandir function in PHP, then choose which file to open.


  • Read the contents of a file and display it in a textarea.

In PHP, file_get_contents() function is one of the file handling functions available in this scripting language. This function reads entire file source or part of it and returns as a PHP string data. Because it will use memory mapping techniques, if this is supported by the server, to enhance performance. This function is binary-safe (meaning that both binary data, like images, and character data can be written with this function).


  • Save content to file

You create a HTML form to edit the textfile’s content. In case it get’s submitted, you update the file.

The file_put_contents() writes a string to a file. Specifies the file to write to. If the file does not exist, this function will create one. Always use full paths and make sure the directory is writable.



Prakash S

Prakash S

I would like to introduce myself as a Software professional opting for the career in software industry. I'm Prakash S, a MCA graduate and trained as industry level practice for Software technology. Basically I am a PHP Developer but now days exploring more in HTML5, CSS, AngularJS and jQuery libraries.