Class: File_Archive
Source Location: /File_Archive-1.5.5/File/Archive.php
Factory to access the most common File_Archive features
|
|
Inherited Variables
|
Inherited Methods
|
Class Details
Method Detail
appender [line 1361]
File_Archive_Writer appender(
$URL, [
$unique = null], [
$type = null], [
$stat = array()], File_Archive_Reader
$source)
|
|
Create a writer that allows appending new files to an existing archive This function actes as appendToSource with source being the system files $URL can't be null here
Parameters:
appenderFromSource [line 1269]
File_Archive_Writer appenderFromSource(
&$toConvert, [string
$URL = null], [bool
$unique = null], [string
$type = null], [array
$stat = array()], File_Archive_Reader
$source)
|
|
Create a writer that can be used to append files to an archive inside a source If the archive can't be found in the source, it will be created If source is set to null, File_Archive::toFiles will be assumed If type is set to null, the type of the archive will be determined looking at the extension in the URL stat is the array of stat (returned by stat() PHP function of Reader getStat()) to use if the archive must be created This function allows to create or append data to nested archives. Only one archive will be created and if your creation requires creating several nested archives, a PEAR error will be returned After this call, $source will be closed and should not be used until the returned writer is closed.
Parameters:
cache [line 549]
void cache(
&$toConvert, mixed
$toConvert)
|
|
Adds a cache layer above the specified reader The data of the reader is saved in a temporary file for future access. The cached reader will be read only once, even if you read it several times. This can be usefull to read compressed files or downloaded files (from http or ftp)
Parameters:
changeName [line 783]
File_Archive_Reader changeName(
Callable
$function,
&$toConvert, File_Archive_Reader
$toConvert)
|
|
Changes the name of each file in a reader by applying a custom function The function must return false if the file is to be discarded, or the new name of the file else
Parameters:
extract [line 1230]
null extract(
&$sourceToConvert,
&$destToConvert, [bool
$autoClose = true], [int
$bufferSize = 0], File_Archive_Reader
$source, File_Archive_Writer
$dest)
|
|
File_Archive::extract($source, $dest) is equivalent to $source->extract($dest) If $source is a PEAR error, the error will be returned It is thus easier to use this function than $source->extract, since it reduces the number of error checking and doesn't force you to define a variable $source You may use strings as source and dest. In that case the source is automatically converted to a reader using File_Archive::read and the dest is converted to a writer using File_Archive::appender Since PHP doesn't allow to pass literal strings by ref, you will have to use temporary variables. File_Archive::extract($src = 'archive.zip/', $dest = 'dir') will extract the archive to 'dir' It is the same as File_Archive::extract( File_Archive::read('archive.zip/'), File_Archive::appender('dir') ); You may use any variable in the extract function ($from/$to, $a/$b...).
Parameters:
filter [line 802]
void filter(
File_Archive_Predicate
$predicate,
&$toConvert, File_Archive_Reader
$source)
|
|
Removes from a source the files that do not follow a given predicat
Parameters:
getOption [line 140]
Retrieve the value of an option
Parameters:
isKnownExtension [line 620]
bool isKnownExtension(
string
$extension)
|
|
Check if a file with a specific extension can be read as an archive with File_Archive::read* This function is case sensitive.
Parameters:
predAnd [line 840]
void predAnd(
File_Archive_Predicate
0)
|
|
Predicate that evaluates to the logical AND of the parameters You can add other predicates thanks to the File_Archive_Predicate_And::addPredicate() function
Parameters:
predCustom [line 1015]
void predCustom(
string
$expression)
|
|
Custom predicate built by supplying a string expression Here are different ways to create a predicate that keeps only files with names shorter than 100 chars <sample> File_Archive::predCustom("return strlen($name)<100;") File_Archive::predCustom("strlen($name)<100;") File_Archive::predCustom("strlen($name)<100") File_Archive::predCustom("strlen($source->getFilename())<100") </sample>
Parameters:
predEreg [line 961]
void predEreg(
string
$ereg)
|
|
Evaluates to true iif the name of the file follow a given regular expression
Parameters:
predEregi [line 974]
void predEregi(
string
$ereg)
|
|
Evaluates to true iif the name of the file follow a given regular expression (case insensitive version)
Parameters:
predExtension [line 921]
void predExtension(
array
$list)
|
|
Evaluates to true iif the extension of the file is in a given list
Parameters:
predFalse [line 827]
Predicate that always evaluate to false
predIndex [line 988]
void predIndex(
array
$indexes)
|
|
Evaluates to true only after a given number of evaluations This can be used to select files by index since the evaluation is done once per file
Parameters:
predMaxDepth [line 909]
void predMaxDepth(
int
$depth)
|
|
Evaluates to true iif the file has less that a given number of directories in its path
Parameters:
predMIME [line 934]
void predMIME(
array
$list)
|
|
Evaluates to true iif the MIME type of the file is in a given list
Parameters:
predMinSize [line 885]
void predMinSize(
int
$size)
|
|
Evaluates to true iif the file is larger than a given size
Parameters:
predMinTime [line 897]
void predMinTime(
int
$time)
|
|
Evaluates to true iif the file has been modified after a given time
Parameters:
predNot [line 874]
void predNot(
File_Archive_Predicate
$pred)
|
|
Negate a predicate
Parameters:
predOr [line 858]
void predOr(
File_Archive_Predicate
0)
|
|
Predicate that evaluates to the logical OR of the parameters You can add other predicates thanks to the File_Archive_Predicate_Or::addPredicate() function
Parameters:
predPreg [line 947]
void predPreg(
string
$preg)
|
|
Evaluates to true iif the name of the file follow a given regular expression
Parameters:
predTrue [line 817]
Predicate that always evaluate to true
read [line 474]
void read(
$URL, [
$symbolic = null], [
$uncompression = 0], [
$directoryDepth = -1])
|
|
Parameters:
readArchive [line 651]
A readArchive(
string
$extension,
&$toConvert, [bool
$sourceOpened = false], File_Archive_Reader
$source)
|
|
Create a reader that will read the single file source $source as a specific archive
Parameters:
readConcat [line 759]
void readConcat(
&$toConvert, string
$filename, [array
$stat = array()], [string
$mime = null], File_Archive_Reader
$toConvert)
|
|
Make the files of a source appear as one large file whose content is the concatenation of the content of all the files
Parameters:
readMemory [line 716]
void readMemory(
string
$memory, string
$filename, [array
$stat = array()], [string
$mime = null])
|
|
Contains only one file with data read from a memory buffer
Parameters:
readMulti [line 732]
void readMulti(
[array
$sources = array()])
|
|
Contains several other sources. Take care the sources don't have several files with the same filename. The sources are given as a parameter, or can be added thanks to the reader addSource method
Parameters:
readSource [line 257]
void readSource(
&$source,
$URL, [
$symbolic = null], [
$uncompression = 0], [
$directoryDepth = -1])
|
|
Create a reader to read the URL $URL. If the URL is a directory, it will recursively read that directory. If $uncompressionLevel is not null, the archives (files with extension tar, zip, gz or tgz) will be considered as directories (up to a depth of $uncompressionLevel if $uncompressionLevel > 0). The reader will only read files with a directory depth of $directoryDepth. It reader will replace the given URL ($URL) with $symbolic in the public filenames The default symbolic name is the last filename in the URL (or '' for directories) Examples: Considere the following file system a.txt
b.tar (archive that contains the following files)
c.txt
d.tgz (archive that contains the following files)
e.txt
dir1/
f.txt
dir2/
g.txt
dir3/
h.tar (archive that contains the following files)
i.txt read('.') will return a reader that gives access to following files (recursively read current dir): a.txt
b.tar
dir2/g.txt
dir2/dir3/h.tar read('.', 'myBaseDir') will return the following reader: myBaseDir/a.txt
myBaseDir/b.tar
myBaseDir/dir2/g.txt
myBaseDir/dir2/dir3/h.tar read('.', '', -1) will return the following reader (uncompress everything) a.txt
b.tar/c.txt
b.tar/d.tgz/e.txt
b.tar/d.tgz/dir1/f.txt
dir2/g.txt
dir2/dir3/h.tar/i.txt read('.', '', 1) will uncompress only one level (so d.tgz will not be uncompressed): a.txt
b.tar/c.txt
b.tar/d.tgz
dir2/g.txt
dir2/dir3/h.tar/i.txt read('.', '', 0, 0) will not recurse into subdirectories a.txt
b.tar read('.', '', 0, 1) will recurse only one level in subdirectories a.txt
b.tar
dir2/g.txt read('.', '', -1, 2) will uncompress everything and recurse in only 2 levels in subdirectories or archives a.txt
b.tar/c.txt
b.tar/d.tgz/e.txt
dir2/g.txt The recursion level is determined by the real path, not the symbolic one. So read('.', 'myBaseDir', -1, 2) will result to the same files: myBaseDir/a.txt
myBaseDir/b.tar/c.txt
myBaseDir/b.tar/d.tgz/e.txt (accepted because the real depth is 2)
myBaseDir/dir2/g.txt Use readSource to do the same thing, reading from a specified reader instead of reading from the system files To read a single file, you can do read('a.txt', 'public_name.txt') If no public name is provided, the default one is the name of the file read('dir2/g.txt') contains the single file named 'g.txt' read('b.tar/c.txt') contains the single file named 'c.txt' Note: This function uncompress files reading their extension The compressed files must have a tar, zip, gz or tgz extension Since it is impossible for some URLs to use is_dir or is_file, this function may not work with URLs containing folders which name ends with such an extension
Parameters:
readUploadedFile [line 494]
File_Archive_Reader readUploadedFile(
string
$name)
|
|
Create a file reader on an uploaded file. The reader will read $_FILES[$name]['tmp_name'] and will have $_FILES[$name]['name'] as a symbolic filename. A PEAR error is returned if one of the following happen - $_FILES[$name] is not set
- $_FILES[$name]['error'] is not 0
- is_uploaded_file returns false
Parameters:
remove [line 1404]
void remove(
$URL
$pred,
$URL)
|
|
Remove the files that follow a given predicate from the archive specified in $URL
Parameters:
removeDuplicates [line 1443]
void removeDuplicates(
$URL)
|
|
Remove duplicates from the archive specified in the URL
Parameters:
removeDuplicatesFromSource [line 1416]
void removeDuplicatesFromSource(
File_Archive_Reader
&$toConvert, [
$URL = null])
|
|
Remove duplicates from a source, keeping the most recent one (or the one that has highest pos in the archive if the files have same date or no date specified)
Parameters:
removeFromSource [line 1376]
void removeFromSource(
&$pred,
&$toConvert, [
$URL = null], File_Archive_Predicate
$pred, File_Archive_Reader
$source)
|
|
Remove the files that follow a given predicate from the source If URL is null, the files will be removed from the source directly Else, URL must link to a source from which the files will be removed
Parameters:
setOption [line 127]
void setOption(
$name,
$value)
|
|
Sets an option that will be used by default by all readers or writers Option names are case sensitive Currently, the following options are used: "cache" Instance of a Cache_Lite object used to cache some compressed data to speed up future compressions of files Default: null (no cache used) "zipCompressionLevel" Value between 0 and 9 specifying the default compression level used by Zip writers (0 no compression, 9 highest compression) Default: 9 "gzCompressionLevel" Value between 0 and 9 specifying the default compression level used by Gz writers (0 no compression, 9 highest compression) Default: 9 "tmpDirectory" Directory where the temporary files generated by File_Archive will be created Default: '.' "appendRemoveDuplicates" If set to true, the appender created will by default remove the file present in the archive when adding a new one. This will slow the appending of files to archives Default: false "blockSize" To transfer data from a reader to a writer, some chunks a read from the source and written to the writer. This parameter controls the size of the chunks Default: 64kB "cacheCondition" This parameter specifies when a cache should be used. When the cache is used, the data of the reader is saved in a temporary file for future access. The cached reader will be read only once, even if you read it several times. This can be usefull to read compressed files or downloaded files (from http or ftp) The possible values for this option are - false: never use cache
- a regexp: A cache will be used if the specified URL matches the regexp
preg_match is used
Default: false Example: '/^(http|ftp):\/\//' will cache all files downloaded via http or ftp
Parameters:
toArchive [line 1125]
void toArchive(
string
$filename,
&$toConvert, [string
$type = null], [array
$stat = array()], [bool
$autoClose = true], File_Archive_Writer
$innerWriter)
|
|
Compress the data to a tar, gz, tar/gz or zip format
Parameters:
toFiles [line 1045]
void toFiles(
[string
$baseDir = ""])
|
|
Write the files on the hard drive
Parameters:
toMail [line 1032]
void toMail(
$to, array
$headers, string
$message, [Mail
$mail = null])
|
|
Send the files as a mail attachment
Parameters:
toMemory [line 1064]
void toMemory(
out
$data)
|
|
Send the content of the files to a memory buffer toMemory returns a writer where the data will be written. In this case, the data is accessible using the getData member toVariable returns a writer that will write into the given variable
Parameters:
toMulti [line 1080]
void toMulti(
&$aC,
&$bC, File_Archive_Writer
$a,)
|
|
Duplicate the writing operation on two writers
Parameters:
toOutput [line 1106]
void toOutput(
[bool
$sendHeaders = true])
|
|
Send the content of the files to the standard output (so to the client for a website)
Parameters:
toVariable [line 1069]
Documentation generated on Mon, 11 Mar 2019 15:48:27 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|
|