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

📄 file.php

📁 This is the script which used on 10minutemail.com for temporary email.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
     * @access  public 
     * @param   string  $filename Name of file to read from
     * @param   mixed   $lock Type of lock to use
     * @return  mixed   PEAR_Error on error or one character of the specified file
     */
    function readChar($filename, $lock = false)
    {
        return File::read($filename, 1, $lock);
    } 

    /**
     * Writes a single character to a file
     * 
     * @access  public 
     * @param   string  $filename Name of file to write to
     * @param   string  $char Character to write
     * @param   string  $mode Mode to use when writing
     * @param   mixed   $lock Type of lock to use
     * @return  mixed   PEAR_Error on error, or 1 on success
     */
    function writeChar($filename, $char, $mode = FILE_MODE_APPEND, $lock = false)
    {
        if (PEAR::isError($fp = &File::_getFilePointer($filename, $mode, $lock))) {
            return $fp;
        }
        if (-1 === @fwrite($fp, $char, 1)) {
            return PEAR::raiseError("Cannot write data: '$data' to file: '$filename'");
        }
        return 1;
    } 

    /**
     * Returns a line of the file (without trailing CRLF).
     * Maximum read line length is FILE_MAX_LINE_READSIZE.
     * 
     * @access  public 
     * @param   string  $filename Name of file to read from
     * @param   boolean $lock Whether file should be locked
     * @return  mixed   PEAR_Error on error or a string containing the line read from file
     */
    function readLine($filename, $lock = false)
    {
        static $filePointers; // Used to prevent unnecessary calls to _getFilePointer()
        
        if (    !isset($filePointers[$filename]) || 
                !is_resource($filePointers[$filename])) {
            if (PEAR::isError($fp = &File::_getFilePointer($filename, FILE_MODE_READ, $lock))) {
                return $fp;
            } 

            $filePointers[$filename] = &$fp;
        } else {
            $fp = &$filePointers[$filename];
        } 

        if (feof($fp)) {
            return false;
        } 
        
        return rtrim(fgets($fp, FILE_MAX_LINE_READSIZE), "\r\n");
    } 

    /**
     * Writes a single line, appending a LF (by default)
     * 
     * @access  public 
     * @param   string  $filename Name of file to write to
     * @param   string  $line Line of data to be written to file
     * @param   string  $mode Write mode, can be either FILE_MODE_WRITE or FILE_MODE_APPEND
     * @param   string  $crlf The CRLF your system is using. UNIX = \n Windows = \r\n Mac = \r
     * @param   mixed   $lock Whether to lock the file
     * @return  mixed   PEAR_Error on error or number of bytes written to file (including appended crlf)
     */
    function writeLine($filename, $line, $mode = FILE_MODE_APPEND, $crlf = "\n", $lock = false)
    {
        if (PEAR::isError($fp = &File::_getFilePointer($filename, $mode, $lock))) {
            return $fp;
        }
        if (-1 === $bytes = fwrite($fp, $line . $crlf)) {
            return PEAR::raiseError("Cannot write data: '$data' to file: '$file'");
        }
        return $bytes;
    } 

    /**
     * This rewinds a filepointer to the start of a file
     * 
     * @access  public 
     * @param   string  $filename The filename
     * @param   string  $mode Mode the file was opened in
     * @return  mixed   PEAR Error on error, true on success
     */
    function rewind($filename, $mode)
    {
        if (PEAR::isError($fp = &File::_getFilePointer($filename, $mode))) {
            return $fp;
        }
        if (!@rewind($fp)) {
            return PEAR::raiseError("Cannot rewind file: $filename");
        }
        return true;
    } 

    /**
     * Closes all open file pointers
     * 
     * @access  public
     * @return  void
     */
    function closeAll()
    {
        $locks = &PEAR::getStaticProperty('File', 'locks');
        $filePointers = &PEAR::getStaticProperty('File', 'filePointers');
        
        // unlock files
        for ($i = 0, $c = count($locks); $i < $c; $i++) {
            is_resource($locks[$i]) and @flock($locks[$i], LOCK_UN);
        }
        
        // close files
        if (!empty($filePointers)) {
            foreach ($filePointers as $fname => $modes) {
                foreach (array_keys($modes) as $mode) {
                    if (is_resource($filePointers[$fname][$mode])) {
                        @fclose($filePointers[$fname][$mode]);
                    }
                    unset($filePointers[$fname][$mode]);
                }
            }
        }
    }
    
    /**
     * This closes an open file pointer
     * 
     * @access  public 
     * @param   string  $filename The filename that was opened
     * @param   string  $mode Mode the file was opened in
     * @return  mixed   PEAR Error on error, true otherwise
     */
    function close($filename, $mode)
    {
        $filePointers = &PEAR::getStaticProperty('File', 'filePointers');
        
        if (!isset($filePointers[$filename][$mode])) {
            return true;
        }
        
        $fp = $filePointers[$filename][$mode];
        unset($filePointers[$filename][$mode]);
        
        if (is_resource($fp)) {
            // unlock file
            @flock($fp, LOCK_UN);
            // close file
            if (!@fclose($fp)) {
                return PEAR::raiseError("Cannot close file: $filename");
            }
        }
        
        return true;
    } 

    /**
     * This unlocks a locked file pointer.
     * 
     * @access  public 
     * @param   string  $filename The filename that was opened
     * @param   string  $mode Mode the file was opened in
     * @return  mixed   PEAR Error on error, true otherwise
     */
    function unlock($filename, $mode)
    {
        if (PEAR::isError($fp = &File::_getFilePointer($filename, $mode))) {
            return $fp;
        }
        if (!@flock($fp, LOCK_UN)) {
            return PEAR::raiseError("Cacnnot unlock file: $filename");
        }
        return true;
    } 

    /**
     * @deprecated
     */
    function stripTrailingSeparators($path, $separator = DIRECTORY_SEPARATOR)
    {
        return rtrim($path, $separator);
    } 

    /**
     * @deprecated
     */
    function stripLeadingSeparators($path, $separator = DIRECTORY_SEPARATOR)
    {
        return ltrim($path, $separator);
    } 

    /**
     * @deprecated      Use File_Util::buildPath() instead.
     */
    function buildPath($parts, $separator = DIRECTORY_SEPARATOR)
    {
        require_once 'File/Util.php';
        return File_Util::buildPath($parts, $separator);
    } 

    /**
     * @deprecated      Use File_Util::skipRoot() instead.
     */
    function skipRoot($path)
    {
        require_once 'File/Util.php';
        return File_Util::skipRoot($path);
    } 

    /**
     * @deprecated      Use File_Util::tmpDir() instead.
     */
    function getTempDir()
    {
        require_once 'File/Util.php';
        return File_Util::tmpDir();
    }

    /**
     * @deprecated      Use File_Util::tmpFile() instead.
     */
    function getTempFile($dirname = null)
    {
        require_once 'File/Util.php';
        return File_Util::tmpFile($dirname);
    } 

    /**
     * @deprecated      Use File_Util::isAbsolute() instead.
     */
    function isAbsolute($path)
    {
        require_once 'File/Util.php';
        return File_Util::isAbsolute($path);
    } 

    /**
     * @deprecated      Use File_Util::relativePath() instead.
     */
    function relativePath($path, $root, $separator = DIRECTORY_SEPARATOR)
    {
        require_once 'File/Util.php';
        return File_Util::relativePath($path, $root, $separator);
    }

    /**
     * @deprecated      Use File_Util::realpath() instead.
     */
    function realpath($path, $separator = DIRECTORY_SEPARATOR)
    {
        require_once 'File/Util.php';
        return File_Util::realpath($path, $separator);
    }
}

PEAR::registerShutdownFunc(array('File', '_File'));

?>

⌨️ 快捷键说明

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