Handling Files in php

php-sniplets Add comments

Handling Files

To apply the file functions, you just need to point them at the file they’ve to read, applying a path that is relative to the PHP script that runs the function. Even so, the absolute majority of PHP file functions use a somewhat another mechanism to get at a file–a mechanism that is really alike to that utilized to connect to a database. The process uses the fclose function to “disconnect and fopen function to “connect”. The value generated from the fopen function is a PHP file pointer, a.k.a. the handle of the file. When we get a handle on a file, we can apply it to execute an assortment of functionings on the file, admitting modifying it, reading to it, append it, etcetera.


This mere example shows how to close and open that “association” to the file:

<?php $location = ‘writeFileHandling.htm’; $fp = fopen($location, ‘rb’);  the file handle $fp is now usable fclose($fp); echo $file; ?>

Once you apply fopen to associate to a file, you must assign the route to the file and a manner in which the file is to be got at (specified r as read only). The b mode indicator shows that the file is to follow open in binary mode. The binary mode had better ever be assigned to ensure the movability of your code ‘tween OSs. For further information about the several modes that are accessible, read the manual here -> http://www.php.net/fopen/

Leave a Reply

You must be logged in to post a comment.

Impressum Entries RSS Log in