Basic PHP File Handling

It's only fair to share...Share on Facebook0Share on Google+3Tweet about this on Twitter0Share on LinkedIn2Pin on Pinterest0Digg thisShare on StumbleUpon0

In this tutorial we will explain, how to work with file operations using PHP. This is one of the most fundamental topics of server side programming including PHP. There are inbuilt PHP function through which we can read, write, create, rename, delete files and much more. This tutorial is basically for those guys who are beginner in this programming language.

Create a File

 Open a Fie:

r      Read only. Starts at the beginning of the file
r+   Read/Write. Starts at the beginning of the file
w     Write only. Opens and clears the contents of file; or creates a new file if it doesn’t exist
w+  Read/Write. Opens and clears the contents of file; or creates a new file if it doesn’t exist
a      Append. Opens and writes to the end of the file or creates a new file if it doesn’t exist
a+   Read/Append. Preserves file content by writing to the end of the file
x      Write only. Creates a new file. Returns FALSE and an error if file already exists
x+    Read/Write. Creates a new file. Returns FALSE and an error if file already exists

Read a File:

 Write to a File:

Append to a File:

 Close a File:

Delete a File:

 Rename a file:

Tags:,

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">