Tag Archives: file

fputcsv

It format line as CSV and write to file pointer

Example

<?php

$data = array ( array(‘php’, ‘asp’, ‘jsp’, ‘js’));

$fp = fopen(‘test.csv’, ‘w’);

foreach ($data as $value) {

fputcsv($fp, $value);

}

fclose($fp);

?>

fpassthru

The fpassthru() function reads all data from the current position in an open file, until EOF, and writes the result to the output buffer.

This function returns the number of characters passed or FALSE on failure.

Example

<?php

$fp = @fopen(“test.txt”, “r”);

fpassthru($fp);

?>

flock

It can be used to lock the file

Example

<?php

$fp = fopen(“test.txt”, “r+”);

flock($fp, LOCK_EX); //  acquire an exclusive lock (writer).

flock($fp, LOCK_SH); // acquire a shared lock (reader).

flock($fp, LOCK_UN); // unlock the file

fclose($fp);

?>