⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 archive.php

📁 太烦了
💻 PHP
📖 第 1 页 / 共 4 页
字号:
                $tmp =& File_Archive::filter(
                    new File_Archive_Predicate_MaxDepth($directoryDepth),
                    $result
                );
                unset($result);
                $result =& $tmp;
            }
            if (!empty($realSymbolic)) {
                if ($symbolic === null) {
                    $realSymbolic = '';
                }
                $tmp =& new File_Archive_Reader_AddBaseName(
                    $realSymbolic,
                    $result
                );
                unset($result);
                $result =& $tmp;
            }

        //If the URL can be interpreted as a file, and we are reading from the file system
        } else if (is_file($URL) && substr($URL, -1)!='/' && $source === null) {
            require_once PEAR_DIR."File/Archive/Reader/File.php";
            $result = new File_Archive_Reader_File($URL, $realSymbolic);

        //Else, we will have to build a complex reader
        } else {
            require_once PEAR_DIR."File/Archive/Reader/File.php";

            $realPath = $std;

            // Try to find a file with a known extension in the path (
            // (to manage URLs like archive.tar/directory/file)
            $pos = 0;
            do {
                if ($pos+1<strlen($realPath)) {
                    $pos = strpos($realPath, '/', $pos+1);
                } else {
                    $pos = false;
                }
                if ($pos === false) {
                    $pos = strlen($realPath);
                }

                $file = substr($realPath, 0, $pos);
                $baseDir = substr($realPath, $pos+1);
                $dotPos = strrpos($file, '.');
                $extension = '';
                if ($dotPos !== false) {
                    $extension = substr($file, $dotPos+1);
                }
            } while ($pos < strlen($realPath) &&
                (!File_Archive::isKnownExtension($extension) ||
                 (is_dir($file) && $source==null)));

            $reachable = $file;

            //If we are reading from the file system
            if ($source === null) {
                //Create a file reader
                $result = new File_Archive_Reader_File($file);
            } else {
                //Select in the source the file $file

                require_once PEAR_DIR."File/Archive/Reader/Select.php";
                $result = new File_Archive_Reader_Select($file, $source);
            }

            require_once PEAR_DIR."File/Archive/Reader/Uncompress.php";
            $tmp = new File_Archive_Reader_Uncompress($result, $uncompressionLevel);
            unset($result);
            $result = $tmp;

            //Select the requested folder in the uncompress reader
            $isDir = $result->setBaseDir($std);
            if (PEAR::isError($isDir)) {
                return $isDir;
            }
            if ($isDir && $symbolic==null) {
                //Default symbolic name for directories is empty
                $realSymbolic = '';
            }

            if ($directoryDepth >= 0) {
                //Limit the maximum depth if necessary
                require_once PEAR_DIR."File/Archive/Predicate/MaxDepth.php";

                $tmp = new File_Archive_Reader_Filter(
                    new File_Archive_Predicate(
                        $directoryDepth +
                        substr_count(substr($std, $pos+1), '/')
                    ),
                    $result
                );
                unset($result);
                $result =& $tmp;
            }

            if ($std != $realSymbolic) {
                require_once PEAR_DIR."File/Archive/Reader/ChangeName.php";

                //Change the base name to the symbolic one if necessary
                $tmp = new File_Archive_Reader_ChangeBaseName(
                    $std,
                    $realSymbolic,
                    $result
                );
                unset($result);
                $result =& $tmp;
            }
        }

        $cacheCondition = File_Archive::getOption('cacheCondition');
        if ($cacheCondition !== false &&
            preg_match($cacheCondition, $URL)) {
            $tmp =& File_Archive::cache($result);
            unset($result);
            $result =& $tmp;
        }

        return $result;
    }
    function read($URL, $symbolic = null,
                  $uncompression = 0, $directoryDepth = -1)
    {
        $source = null;
        return File_Archive::readSource($source, $URL, $symbolic, $uncompression, $directoryDepth);
    }

    /**
     * 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
     *
     * @param string $name Index of the file in the $_FILES array
     * @return File_Archive_Reader File reader on the uploaded file
     */
    function readUploadedFile($name)
    {
        if (!isset($_FILES[$name])) {
            return PEAR::raiseError("File $name has not been uploaded");
        }
        switch ($_FILES[$name]['error']) {
        case 0:
            //No error
            break;
        case 1:
            return PEAR::raiseError(
                        "The upload size limit didn't allow to upload file ".
                        $_FILES[$name]['name']
                    );
        case 2:
            return PEAR::raiseError(
                        "The form size limit didn't allow to upload file ".
                        $_FILES[$name]['name']
                   );
        case 3:
            return PEAR::raiseError(
                        "The file was not entirely uploaded"
                   );
        case 4:
            return PEAR::raiseError(
                        "The uploaded file is empty"
                   );
        default:
            return PEAR::raiseError(
                        "Unknown error ".$_FILES[$name]['error']." in file upload. ".
                        "Please, report a bug"
                   );
        }
        if (!is_uploaded_file($_FILES[$name]['tmp_name'])) {
            return PEAR::raiseError("The file is not an uploaded file");
        }

        require_once PEAR_DIR."File/Archive/Reader/File.php";
        return new File_Archive_Reader_File(
                    $_FILES[$name]['tmp_name'],
                    $_FILES[$name]['name'],
                    $_FILES[$name]['type']
               );
    }

    /**
     * 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)
     *
     * @param mixed $toConvert The reader to cache
     *        It can be a File_Archive_Reader or a string, which will be converted using the
     *        read function
     */
    function cache(&$toConvert)
    {
        $source =& File_Archive::_convertToReader($toConvert);
        if (PEAR::isError($source)) {
            return $source;
        }

        require_once PEAR_DIR.'File/Archive/Reader/Cache.php';
        return new File_Archive_Reader_Cache($source);
    }

    /**
     * Try to interpret the object as a reader
     * Strings are converted to readers using File_Archive::read
     * Arrays are converted to readers using File_Archive::readMulti
     *
     * @access private
     */
    function &_convertToReader(&$source)
    {
        if (is_string($source)) {
            $cacheCondition = File_Archive::getOption('cacheCondition');
            if ($cacheCondition !== false &&
                preg_match($cacheCondition, $source)) {
                return File_Archive::cache(File_Archive::read($source));
            } else {
                return File_Archive::read($source);
            }
        } else if (is_array($source)) {
            return File_Archive::readMulti($source);
        } else {
            return $source;
        }
     }

    /**
     * Try to interpret the object as a writer
     * Strings are converted to writers using File_Archive::appender
     * Arrays are converted to writers using a multi writer
     *
     * @access private
     */
    function &_convertToWriter(&$dest)
    {
        if (is_string($dest)) {
            return File_Archive::appender($dest);
        } else if (is_array($dest)) {
            require_once PEAR_DIR.'File/Archive/Writer/Multi.php';
            $writer = new File_Archive_Writer_Multi();
            foreach($dest as $key => $foo) {
                $writer->addWriter($dest[$key]);
            }
        } else {
            return $dest;
        }
    }

    /**
     * Check if a file with a specific extension can be read as an archive
     * with File_Archive::read*
     * This function is case sensitive.
     *
     * @param string $extension the checked extension
     * @return bool whether this file can be understood reading its extension
     *         Currently, supported extensions are tar, zip, gz, tgz, tbz, bz2,
     *         bzip2, ar, deb
     */
    function isKnownExtension($extension)
    {
        return $extension == 'tar'   ||
               $extension == 'zip'   ||
               $extension == 'gz'    ||
               $extension == 'tgz'   ||
               $extension == 'tbz'   ||
               $extension == 'bz2'   ||
               $extension == 'bzip2' ||
               $extension == 'ar'    ||
               $extension == 'deb'   /* ||
               $extension == 'cab'   ||
               $extension == 'rar' */;
    }

    /**
     * Create a reader that will read the single file source $source as
     * a specific archive
     *
     * @param string $extension determines the kind of archive $source contains
     *        $extension is case sensitive
     * @param File_Archive_Reader $source stores the archive
     * @param bool $sourceOpened specifies if the archive is already opened
     *        if false, next will be called on source
     *        Closing the returned archive will close $source iif $sourceOpened
     *        is true
     * @return A File_Archive_Reader that uncompresses the archive contained in
     *         $source interpreting it as a $extension archive
     *         If $extension is not handled return false
     */
    function readArchive($extension, &$toConvert, $sourceOpened = false)
    {
        $source =& File_Archive::_convertToReader($toConvert);
        if (PEAR::isError($source)) {
            return $source;
        }

        switch($extension) {
        case 'tgz':
            return File_Archive::readArchive('tar',
                    File_Archive::readArchive('gz', $source, $sourceOpened)
                    );
        case 'tbz':
            return File_Archive::readArchive('tar',
                    File_Archive::readArchive('bz2', $source, $sourceOpened)
                    );
        case 'tar':
            require_once PEAR_DIR.'File/Archive/Reader/Tar.php';
            return new File_Archive_Reader_Tar($source, $sourceOpened);

        case 'gz':
        case 'gzip':
            require_once PEAR_DIR.'File/Archive/Reader/Gzip.php';
            return new File_Archive_Reader_Gzip($source, $sourceOpened);

        case 'zip':
            require_once PEAR_DIR.'File/Archive/Reader/Zip.php';
            return new File_Archive_Reader_Zip($source, $sourceOpened);

        case 'bz2':
        case 'bzip2':
            require_once PEAR_DIR.'File/Archive/Reader/Bzip2.php';
            return new File_Archive_Reader_Bzip2($source, $sourceOpened);

        case 'deb':
        case 'ar':
            require_once PEAR_DIR.'File/Archive/Reader/Ar.php';
            return new File_Archive_Reader_Ar($source, $sourceOpened);

/*        case 'cab':
            require_once 'File/Archive/Reader/Cab.php';
            return new File_Archive_Reader_Cab($source, $sourceOpened);


        case 'rar':
            require_once "File/Archive/Reader/Rar.php";
            return new File_Archive_Reader_Rar($source, $sourceOpened); */

        default:
            return false;
        }
    }

    /**
     * Contains only one file with data read from a memory buffer
     *
     * @param string $memory content of the file
     * @param string $filename public name of the file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -