PHP Classes

File: test.file.class.php

Recommend this page to a friend!
  Classes of Mike Leigh   phpFile   test.file.class.php   Download  
File: test.file.class.php
Role: Example script
Content type: text/plain
Description: Example Usage
Class: phpFile
Create files and manipulate their contents
Author: By
Last change: See the CHANGELOG file for the summary of changes to this version
Date: 17 years ago
Size: 2,449 bytes
 

Contents

Class file image Download
<?php
#===========================================================================
#= Script : phpFile
#= File : test.file.class.php
#= Version: 0.2
#= Author : Mike Leigh
#= Email : mike@mikeleigh.com
#= Website: http://www.mikeleigh.com/scripts/phpfile
#= Support: http://www.mikeleigh.com/forum
#===========================================================================
#= Copyright (c) 2006 Mike Leigh
#= You are free to use and modify this script as long as this header
#= section stays intact
#=
#= This file is part of phpFile.
#=
#= phpFile is free software; you can redistribute it and/or modify
#= it under the terms of the GNU General Public License as published by
#= the Free Software Foundation; either version 2 of the License, or
#= (at your option) any later version.
#=
#= phpFile is distributed in the hope that it will be useful,
#= but WITHOUT ANY WARRANTY; without even the implied warranty of
#= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#= GNU General Public License for more details.
#=
#= You should have received a copy of the GNU General Public License
#= along with DownloadCounter; if not, write to the Free Software
#= Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#===========================================================================
include('./file.class.php');

//creates a new file called new_file.txt and writes some text to it
$file = new phpFile();
$file->open('new_file.txt', 'w');
$file->write("0123456789");
$file->save();
$file->close();

//open the file created and append a line to the end of the file
$file = new phpFile();
$file->open('new_file.txt', 'a');
$file->write("\r\na line appended to the file");
$file->save();
$file->close();

//open the file created and insert some at offset 0
for($i = 0; $i <= 10; $i++) {
   
$file = new phpFile();
   
$file->setMode('a');
   
$file->open('new_file.txt');
   
$file->write($i."\r\n");
   
$file->insert(0);
   
$file->save();
   
$file->close();
}

//open the file created and insert text at offset 19
$file = new phpFile();
$file->setMode('a');
$file->open('new_file.txt');
$file->write('text');
$file->insert(19);
$file->save();
$file->close();

//open the file created and remove text between offset 19 and 21
$file = new phpFile();
$file->setMode('a');
$file->open('new_file.txt');
$file->remove(19, 21);
$file->save();
$file->close();
?>