📄 archive.php
字号:
* @param array $stat statistics of the file. Index 7 (size) will be
* overwritten to match the size of $memory
* @param string $mime mime type of the file. Default will determine the
* mime type thanks to the extension of $filename
* @see File_Archive_Reader_Memory
*/
function readMemory($memory, $filename, $stat=array(), $mime=null)
{
require_once PEAR_DIR."File/Archive/Reader/Memory.php";
return new File_Archive_Reader_Memory($memory, $filename, $stat, $mime);
}
/**
* 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
*
* @param array $sources Array of strings or readers that will be added to
* the multi reader. If the parameter is a string, a reader will be
* built thanks to the read function
* @see File_Archive_Reader_Multi, File_Archive::read()
*/
function readMulti($sources = array())
{
require_once PEAR_DIR."File/Archive/Reader/Multi.php";
$result = new File_Archive_Reader_Multi();
foreach ($sources as $index => $foo) {
$s =& File_Archive::_convertToReader($sources[$index]);
if (PEAR::isError($s)) {
return $s;
} else {
$result->addSource($s);
}
}
return $result;
}
/**
* Make the files of a source appear as one large file whose content is the
* concatenation of the content of all the files
*
* @param File_Archive_Reader $source The source whose files must be
* concatened
* @param string $filename name of the only file of the created reader
* @param array $stat statistics of the file. Index 7 (size) will be
* overwritten to match the total size of the files
* @param string $mime mime type of the file. Default will determine the
* mime type thanks to the extension of $filename
* @see File_Archive_Reader_Concat
*/
function readConcat(&$toConvert, $filename, $stat=array(), $mime=null)
{
$source =& File_Archive::_convertToReader($toConvert);
if (PEAR::isError($source)) {
return $source;
}
require_once PEAR_DIR."File/Archive/Reader/Concat.php";
return new File_Archive_Reader_Concat($source, $filename, $stat, $mime);
}
/**
* Removes from a source the files that do not follow a given predicat
*
* @param File_Archive_Predicate $predicate Only the files for which
* $predicate->isTrue() will be kept
* @param File_Archive_Reader $source Source that will be filtered
* @see File_Archive_Reader_Filter
*/
function filter($predicate, &$toConvert)
{
$source =& File_Archive::_convertToReader($toConvert);
if (PEAR::isError($source)) {
return $source;
}
require_once PEAR_DIR."File/Archive/Reader/Filter.php";
return new File_Archive_Reader_Filter($predicate, $source);
}
/**
* Predicate that always evaluate to true
*
* @see File_Archive_Predicate_True
*/
function predTrue()
{
require_once PEAR_DIR."File/Archive/Predicate/True.php";
return new File_Archive_Predicate_True();
}
/**
* Predicate that always evaluate to false
*
* @see File_Archive_Predicate_False
*/
function predFalse()
{
require_once PEAR_DIR."File/Archive/Predicate/False.php";
return new File_Archive_Predicate_False();
}
/**
* Predicate that evaluates to the logical AND of the parameters
* You can add other predicates thanks to the
* File_Archive_Predicate_And::addPredicate() function
*
* @param File_Archive_Predicate (any number of them)
* @see File_Archive_Predicate_And
*/
function predAnd()
{
require_once PEAR_DIR."File/Archive/Predicate/And.php";
$pred = new File_Archive_Predicate_And();
$args = func_get_args();
foreach ($args as $p) {
$pred->addPredicate($p);
}
return $pred;
}
/**
* Predicate that evaluates to the logical OR of the parameters
* You can add other predicates thanks to the
* File_Archive_Predicate_Or::addPredicate() function
*
* @param File_Archive_Predicate (any number of them)
* @see File_Archive_Predicate_Or
*/
function predOr()
{
require_once PEAR_DIR."File/Archive/Predicate/Or.php";
$pred = new File_Archive_Predicate_Or();
$args = func_get_args();
foreach ($args as $p) {
$pred->addPredicate($p);
}
return $pred;
}
/**
* Negate a predicate
*
* @param File_Archive_Predicate $pred Predicate to negate
* @see File_Archive_Predicate_Not
*/
function predNot($pred)
{
require_once PEAR_DIR."File/Archive/Predicate/Not.php";
return new File_Archive_Predicate_Not($pred);
}
/**
* Evaluates to true iif the file is larger than a given size
*
* @param int $size the minimal size of the files (in Bytes)
* @see File_Archive_Predicate_MinSize
*/
function predMinSize($size)
{
require_once PEAR_DIR."File/Archive/Predicate/MinSize.php";
return new File_Archive_Predicate_MinSize($size);
}
/**
* Evaluates to true iif the file has been modified after a given time
*
* @param int $time Unix timestamp of the minimal modification time of the
* files
* @see File_Archive_Predicate_MinTime
*/
function predMinTime($time)
{
require_once PEAR_DIR."File/Archive/Predicate/MinTime.php";
return new File_Archive_Predicate_MinTime($time);
}
/**
* Evaluates to true iif the file has less that a given number of
* directories in its path
*
* @param int $depth Maximal number of directories in path of the files
* @see File_Archive_Predicate_MaxDepth
*/
function predMaxDepth($depth)
{
require_once PEAR_DIR."File/Archive/Predicate/MaxDepth.php";
return new File_Archive_Predicate_MaxDepth($depth);
}
/**
* Evaluates to true iif the extension of the file is in a given list
*
* @param array or string $list List or comma separated string of possible
* extension of the files
* @see File_Archive_Predicate_Extension
*/
function predExtension($list)
{
require_once PEAR_DIR."File/Archive/Predicate/Extension.php";
return new File_Archive_Predicate_Extension($list);
}
/**
* Evaluates to true iif the MIME type of the file is in a given list
*
* @param array or string $list List or comma separated string of possible
* MIME types of the files. You may enter wildcards like "image/*" to
* select all the MIME in class image
* @see File_Archive_Predicate_MIME, MIME_Type::isWildcard()
*/
function predMIME($list)
{
require_once PEAR_DIR."File/Archive/Predicate/MIME.php";
return new File_Archive_Predicate_MIME($list);
}
/**
* Evaluates to true iif the name of the file follow a given regular
* expression
*
* @param string $ereg regular expression that the filename must follow
* @see File_Archive_Predicate_Ereg, ereg()
*/
function predEreg($ereg)
{
require_once PEAR_DIR."File/Archive/Predicate/Ereg.php";
return new File_Archive_Predicate_Ereg($ereg);
}
/**
* Evaluates to true iif the name of the file follow a given regular
* expression (case insensitive version)
*
* @param string $ereg regular expression that the filename must follow
* @see File_Archive_Predicate_Eregi, eregi
*/
function predEregi($ereg)
{
require_once PEAR_DIR."File/Archive/Predicate/Eregi.php";
return new File_Archive_Predicate_Eregi($ereg);
}
/**
* 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
*
* @param array The indexes for which the returned predicate will return true
* are the keys of the array
* The predicate will return true if isset($indexes[$pos])
*/
function predIndex($indexes)
{
require_once PEAR_DIR."File/Archive/Predicate/Index.php";
return new File_Archive_Predicate_Index($indexes);
}
/**
* 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>
*
* @param string $expression String containing an expression that evaluates
* to a boolean. If the expression doesn't contain a return
* statement, it will be added at the begining of the expression
* A ';' will be added at the end of the expression so that you don't
* have to write it. You may use the $name variable to refer to the
* current filename (with path...), $time for the modification time
* (unix timestamp), $size for the size of the file in bytes, $mime
* for the MIME type of the file
* @see File_Archive_Predicate_Custom
*/
function predCustom($expression)
{
require_once PEAR_DIR."File/Archive/Predicate/Custom.php";
return new File_Archive_Predicate_Custom($expression);
}
/**
* Send the files as a mail attachment
*
* @param Mail $mail Object used to send mail (see Mail::factory)
* @param array or String $to An array or a string with comma separated
* recipients
* @param array $headers The headers that will be passed to the Mail_mime
* object
* @param string $message Text body of the mail
* @see File_Archive_Writer_Mail
*/
function toMail($to, $headers, $message, $mail = null)
{
require_once PEAR_DIR."File/Archive/Writer/Mail.php";
return new File_Archive_Writer_Mail($to, $headers, $message, $mail);
}
/**
* Write the files on the hard drive
*
* @param string $baseDir if specified, the files will be created in that
* directory. If they don't exist, the directories will automatically
* be created
* @see File_Archive_Writer_Files
*/
function toFiles($baseDir = "")
{
require_once PEAR_DIR."File/Archive/Writer/Files.php";
return new File_Archive_Writer_Files($baseDir);
}
/**
* 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
*
* @param out $data if specified, the data will be written to this buffer
* Else, you can retrieve the buffer with the
* File_Archive_Writer_Memory::getData() function
* @see File_Archive_Writer_Memory
*/
function toMemory()
{
$v = '';
return File_Archive::toVariable($v);
}
function toVariable(&$v)
{
require_once PEAR_DIR."File/Archive/Writer/Memory.php";
return new File_Archive_Writer_Memory($v);
}
/**
* Duplicate the writing operation on two writers
*
* @param File_Archive_Writer $a, $b writers where data will be duplicated
* @see File_Archive_Writer_Multi
*/
function toMulti(&$aC, &$bC)
{
$a =& File_Archive::_convertToWriter($aC);
$b =& File_Archive::_convertToWriter($bC);
if (PEAR::isError($a)) {
return $a;
}
if (PEAR::isError($b)) {
return $b;
}
require_once PEAR_DIR."File/Archive/Writer/Multi.php";
$writer = new File_Archive_Writer_Multi();
$writer->addWriter($a);
$writer->addWriter($b);
return $writer;
}
/**
* Send the content of the files to the standard output (so to the client
* for a website)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -