|
|
|
|
|
|
| |
| <?php
/**
* filesplit class : Split big text files in multiple files
*
* @package
* @author Ben Yacoub Hatem <hatem@php.net>
* @copyright Copyright (c) 2004
* @version $Id$ - 29/05/2004 09:02:10 - filesplit.class.php
* @access public
**/
class filesplit{
/**
* Constructor
* @access protected
*/
function filesplit(){
}
/**
* File to split
* @access private
* @var string
**/
var $_source = 'logs.txt';
/**
*
* @access public
* @return string
**/
function Getsource(){
return $this->_source;
}
/**
*
* @access public
* @return void
**/
function Setsource($newValue){
$this->_source = $newValue;
}
/**
* how much lines per file
* @access private
* @var integer
**/
var $_lines = 1000;
/**
*
* @access public
* @return integer
**/
function Getlines(){
return $this->_lines;
}
/**
*
* @access public
* @return void
**/
function Setlines($newValue){
$this->_lines = $newValue;
}
/**
* Folder to create splitted files with trail slash at end
* @access private
* @var string
**/
var $_path = 'logs/';
/**
*
* @access public
* @return string
**/
function Getpath(){
return $this->_path;
}
/**
*
* @access public
* @return void
**/
function Setpath($newValue){
$this->_path = $newValue;
}
/**
* Configure the class
* @access public
* @return void
**/
function configure($source = "",$path = "",$lines = ""){
if ($source != "") {
$this->Setsource($source);
}
if ($path!="") {
$this->Setpath($path);
}
if ($lines!="") {
$this->Setlines($lines);
}
}
/**
*
* @access public
* @return void
**/
function run(){
$i=0;
$j=1;
$date = date("m-d-y");
unset($buffer);
$handle = @fopen ($this->Getsource(), "r");
while (!feof ($handle)) {
$buffer .= @fgets($handle, 4096);
$i++;
if ($i >= $split) {
$fname = $this->Getpath()."part.$date.$j.txt";
if (!$fhandle = @fopen($fname, 'w')) {
print "Cannot open file ($fname)";
exit;
}
if (!@fwrite($fhandle, $buffer)) {
print "Cannot write to file ($fname)";
exit;
}
fclose($fhandle);
$j++;
unset($buffer,$i);
}
}
fclose ($handle);
}
}
?> | |
Usage Example
| <?php
/**
* Sample usage of the filesplit class
*
* @package filesplit
* @author Ben Yacoub Hatem <hatem@php.net>
* @copyright Copyright (c) 2004
* @version $Id$ - 29/05/2004 09:14:06 - usage.php
* @access public
**/
require_once("filesplit.class.php");
$s = new filesplit;
/*
$s->Setsource("logs.txt");
$s->Setpath("logs/");
$s->Setlines(100); //number of lines that each new file will have after the split.
*/
$s->configure("logs.txt", "logs/", 2000);
$s->run();
?> | | |
|
| An efficient iterative and buffered text file reader Categories : PHP, Classes and Objects, Filesystem, PHP Classes, Log Files | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | Class that allows the PHP developer to create and manage UNIX like password files suitable for use as Apache authentication password files.
Categories : HTTP, PHP, PHP Classes, Filesystem | | | PHP Based Apache + Mysql Error Log Parser Categories : PHP, PHP Classes, Apache, MySQL, Log Files | | | 3 lines of Code to extract Tar, Zip, Gzip etc.. Categories : PHP, Filesystem, PHP Classes, Compression | | | Easy upload class Categories : PHP Classes, Filesystem, HTTP, PHP | | | A File Browser Class.To Read Drives,Directories and Files .Files writing is also possible Categories : PHP, PHP Classes, Filesystem | | | Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support Categories : PHP, FTP, Filesystem, PHP Classes, Compression | | | Search and Replace Text : Searches Files for Specified Text and Replaces It by a Given Text Categories : PHP, PHP Classes, Search, Filesystem | | | Bs_IniHandler is a class that can read and write ini-style files (and strings) Categories : PHP, Filesystem, PHP Classes | | | Compare two texts and display a block of text with the differences between them. Categories : PHP, PHP Classes, Filesystem, Strings, Arrays | | | PHP4 DirectoryIterator Class Categories : PHP, PHP Classes, Filesystem, Directories | | | logger class (PHP5 +) Categories : PHP, PHP Classes, Log Files, XML | | | PHP Transfer data from text file to Mysql Table Categories : PHP, PHP Classes, Filesystem, Databases, MySQL | | | Scan Apache access log files and report possible worms attack Categories : PHP, PHP Classes, Security, Apache, Log Files | |
|
|
|