VFS
[ class tree: VFS ] [ index: VFS ] [ all elements ]

Source for file file.php

Documentation is available at file.php

  1. <?php
  2. /**
  3.  * VFS implementation for a standard filesystem.
  4.  *
  5.  * Required parameters:<pre>
  6.  *   'vfsroot'  The root path</pre>
  7.  *
  8.  * Note: The user that your webserver runs as (commonly 'nobody',
  9.  * 'apache', or 'www-data') MUST have read/write permission to the
  10.  * directory you specify as the 'vfsroot'.
  11.  *
  12.  * $Horde: framework/VFS/lib/VFS/file.php,v 1.2 2008/01/02 11:12:24 jan Exp $
  13.  *
  14.  * Copyright 2002-2008 The Horde Project (http://www.horde.org/)
  15.  *
  16.  * See the enclosed file COPYING for license information (LGPL). If you
  17.  * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  18.  *
  19.  * @author  Chuck Hagenbuch
  20.  * @package VFS
  21.  */
  22. class VFS_file extends VFS {
  23.  
  24.     /**
  25.      * List of permissions and if they can be changed in this VFS
  26.      * backend.
  27.      *
  28.      * @var array 
  29.      */
  30.     var $_permissions = array(
  31.         'owner' => array('read' => true'write' => true'execute' => true),
  32.         'group' => array('read' => true'write' => true'execute' => true),
  33.         'all'   => array('read' => true'write' => true'execute' => true)
  34.     );
  35.  
  36.     /**
  37.      * Constructs a new Filesystem based VFS object.
  38.      *
  39.      * @param array $params  A hash containing connection parameters.
  40.      */
  41.     function VFS_file($params = array())
  42.     {
  43.         parent::VFS($params);
  44.  
  45.         if (!empty($this->_params['vfsroot'])) {
  46.             if (substr($this->_params['vfsroot']-1== '/' ||
  47.                 substr($this->_params['vfsroot']-1== '\\'{
  48.                 $this->_params['vfsroot'substr($this->_params['vfsroot']0strlen($this->_params['vfsroot']- 1);
  49.             }
  50.         }
  51.     }
  52.  
  53.     /**
  54.      * Retrieves the filesize from the VFS.
  55.      *
  56.      * @param string $path  The pathname to the file.
  57.      * @param string $name  The filename to retrieve.
  58.      *
  59.      * @return integer The file size.
  60.      */
  61.     function size($path$name)
  62.     {
  63.         $size @filesize($this->_getNativePath($path$name));
  64.         if ($size === false{
  65.             return PEAR::raiseError(sprintf(_("Unable to check file size of \"%s/%s\".")$path$name));
  66.         }
  67.         return $size;
  68.     }
  69.  
  70.     /**
  71.      * Open a stream to a file in the VFS.
  72.      *
  73.      * @param string $path  The pathname to the file.
  74.      * @param string $name  The filename to retrieve.
  75.      *
  76.      * @return resource  The stream.
  77.      */
  78.     function getStream($path$name)
  79.     {
  80.         if (OS_WINDOWS{
  81.             $mode 'rb';
  82.         else {
  83.             $mode 'r';
  84.         }
  85.         $stream @fopen($this->_getNativePath($path$name)$mode);
  86.         if (!is_resource($stream)) {
  87.             return PEAR::raiseError(_("Unable to open VFS file."));
  88.         }
  89.  
  90.         return $stream;
  91.     }
  92.  
  93.     /**
  94.      * Retrieve a file from the VFS.
  95.      *
  96.      * @param string $path  The pathname to the file.
  97.      * @param string $name  The filename to retrieve.
  98.      *
  99.      * @return string  The file data.
  100.      */
  101.     function read($path$name)
  102.     {
  103.         $data @file_get_contents($this->_getNativePath($path$name));
  104.         if ($data === false{
  105.             return PEAR::raiseError(_("Unable to open VFS file."));
  106.         }
  107.  
  108.         return $data;
  109.     }
  110.  
  111.     /**
  112.      * Retrieves a part of a file from the VFS. Particularly useful when
  113.      * reading large files which would exceed the PHP memory limits if they
  114.      * were stored in a string.
  115.      *
  116.      * @abstract
  117.      *
  118.      * @param string  $path       The pathname to the file.
  119.      * @param string  $name       The filename to retrieve.
  120.      * @param integer $offset     The offset of the part. (The new offset will
  121.      *                             be stored in here).
  122.      * @param integer $length     The length of the part. If the length = -1,
  123.      *                             the whole part after the offset is retrieved.
  124.      *                             If more bytes are given as exists after the
  125.      *                             given offset. Only the available bytes are
  126.      *                             read.
  127.      * @param integer $remaining  The bytes that are left, after the part that
  128.      *                             is retrieved.
  129.      *
  130.      * @return string The file data.
  131.      */
  132.     function readByteRange($path$name&$offset$length = -1&$remaining)
  133.     {
  134.         if ($offset < 0{
  135.             return PEAR::raiseError(sprintf(_("Wrong offset %d while reading a VFS file.")$offset));
  136.         }
  137.  
  138.         // Calculate how many bytes MUST be read, so the remainging
  139.         // bytes and the new offset can be calculated correctly.
  140.         $file $this->_getNativePath($path$name);
  141.         $size filesize ($file);
  142.         if ($length == -1 || (($length $offset$size)) {
  143.             $length $size $offset;
  144.         }
  145.         if ($remaining < 0{
  146.             $remaining = 0;
  147.         }
  148.  
  149.         $fp @fopen($file'rb');
  150.         if (!$fp{
  151.             return PEAR::raiseError(_("Unable to open VFS file."));
  152.         }
  153.         fseek($fp$offset);
  154.         $data fread($fp$length);
  155.         $offset ftell($fp);
  156.         $remaining $size $offset;
  157.  
  158.         fclose($fp);
  159.  
  160.         return $data;
  161.     }
  162.  
  163.     /**
  164.      * Store a file in the VFS, with the data copied from a temporary
  165.      * file.
  166.      *
  167.      * @param string $path         The path to store the file in.
  168.      * @param string $name         The filename to use.
  169.      * @param string $tmpFile      The temporary file containing the data to be
  170.      *                              stored.
  171.      * @param boolean $autocreate  Automatically create directories?
  172.      *
  173.      * @return mixed  True on success or a PEAR_Error object on failure.
  174.      */
  175.     function write($path$name$tmpFile$autocreate = true)
  176.     {
  177.         if (!@is_dir($this->_getNativePath($path))) {
  178.             if ($autocreate{
  179.                 $res $this->autocreatePath($path);
  180.                 if (is_a($res'PEAR_Error')) {
  181.                     return $res;
  182.                 }
  183.             else {
  184.                 return PEAR::raiseError(_("VFS directory does not exist."));
  185.             }
  186.         }
  187.  
  188.         $res $this->_checkQuotaWrite('file'$tmpFile);
  189.         if (is_a($res'PEAR_Error')) {
  190.             return $res;
  191.         }
  192.  
  193.         // Since we already have the data in a file, don't read it
  194.         // into PHP's memory at all - just copy() it to the new
  195.         // location. We leave it to the caller to clean up the
  196.         // temporary file, so we don't use rename().
  197.         if (@copy($tmpFile$this->_getNativePath($path$name))) {
  198.             return true;
  199.         else {
  200.             return PEAR::raiseError(_("Unable to write VFS file (copy() failed)."));
  201.         }
  202.     }
  203.  
  204.     /**
  205.      * Moves a file in the database and the file system.
  206.      *
  207.      * @param string $path         The path to store the file in.
  208.      * @param string $name         The filename to use.
  209.      * @param string $dest         The destination of the file.
  210.      * @param boolean $autocreate  Automatically create directories?
  211.      *
  212.      * @return mixed  True on success or a PEAR_Error object on failure.
  213.      */
  214.     function move($path$name$dest$autocreate = false)
  215.     {
  216.         $orig $this->_getNativePath($path$name);
  217.         if (preg_match('|^' preg_quote($orig'/?$|'$dest)) {
  218.             return PEAR::raiseError(_("Cannot move file(s) - destination is within source."));
  219.         }
  220.  
  221.         if ($autocreate{
  222.             $result $this->autocreatePath($dest);
  223.             if (is_a($result'PEAR_Error')) {
  224.                 return $result;
  225.             }
  226.         }
  227.  
  228.         $fileCheck $this->listFolder($destfalse);
  229.         if (is_a($fileCheck'PEAR_Error')) {
  230.             return $fileCheck;
  231.         }
  232.         foreach ($fileCheck as $file{
  233.             if ($file['name'== $name{
  234.                 return PEAR::raiseError(_("Unable to move VFS file."));
  235.             }
  236.         }
  237.  
  238.         if (!@rename($orig$this->_getNativePath($dest$name))) {
  239.             return PEAR::raiseError(_("Unable to move VFS file."));
  240.         }
  241.  
  242.         return true;
  243.     }
  244.  
  245.     /**
  246.      * Copies a file through the backend.
  247.      *
  248.      * @param string $path         The path to store the file in.
  249.      * @param string $name         The filename to use.
  250.      * @param string $dest         The destination of the file.
  251.      * @param boolean $autocreate  Automatically create directories?
  252.      *
  253.      * @return mixed  True on success or a PEAR_Error object on failure.
  254.      */
  255.     function copy($path$name$dest$autocreate = false)
  256.     {
  257.         $orig $this->_getNativePath($path$name);
  258.         if (preg_match('|^' preg_quote($orig'/?$|'$dest)) {
  259.             return PEAR::raiseError(_("Cannot copy file(s) - source and destination are the same."));
  260.         }
  261.  
  262.         if ($autocreate{
  263.             $result $this->autocreatePath($dest);
  264.             if (is_a($result'PEAR_Error')) {
  265.                 return $result;
  266.             }
  267.         }
  268.  
  269.         $fileCheck $this->listFolder($destfalse);
  270.         if (is_a($fileCheck'PEAR_Error')) {
  271.             return $fileCheck;
  272.         }
  273.         foreach ($fileCheck as $file{
  274.             if ($file['name'== $name{
  275.                 return PEAR::raiseError(_("Unable to copy VFS file."));
  276.             }
  277.         }
  278.  
  279.         if (!@copy($orig$this->_getNativePath($dest$name))) {
  280.             return PEAR::raiseError(_("Unable to copy VFS file."));
  281.         }
  282.  
  283.         return true;
  284.     }
  285.  
  286.     /**
  287.      * Store a file in the VFS from raw data.
  288.      *
  289.      * @param string $path         The path to store the file in.
  290.      * @param string $name         The filename to use.
  291.      * @param string $data         The file data.
  292.      * @param boolean $autocreate  Automatically create directories?
  293.      *
  294.      * @return mixed  True on success or a PEAR_Error object on failure.
  295.      */
  296.     function writeData($path$name$data$autocreate = true)
  297.     {
  298.         if (!@is_dir($this->_getNativePath($path))) {
  299.             if ($autocreate{
  300.                 $res $this->autocreatePath($path);
  301.                 if (is_a($res'PEAR_Error')) {
  302.                     return $res;
  303.                 }
  304.             else {
  305.                 return PEAR::raiseError(_("VFS directory does not exist."));
  306.             }
  307.         }
  308.  
  309.         // Treat an attempt to write an empty file as a touch() call,
  310.         // since otherwise the file will not be created at all.
  311.         if (!strlen($data)) {
  312.             if (@touch($this->_getNativePath($path$name))) {
  313.                 return true;
  314.             else {
  315.                 return PEAR::raiseError(_("Unable to create empty VFS file."));
  316.             }
  317.         }
  318.  
  319.         $res $this->_checkQuotaWrite('string'$data);
  320.         if (is_a($res'PEAR_Error')) {
  321.             return $res;
  322.         }
  323.  
  324.         // Otherwise we go ahead and try to write out the file.
  325.         $fp @fopen($this->_getNativePath($path$name)'w');
  326.         if (!$fp{
  327.             return PEAR::raiseError(_("Unable to open VFS file for writing."));
  328.         }
  329.  
  330.         if (!@fwrite($fp$data)) {
  331.             return PEAR::raiseError(_("Unable to write VFS file data."));
  332.         }
  333.  
  334.         return true;
  335.     }
  336.  
  337.     /**
  338.      * Delete a file from the VFS.
  339.      *
  340.      * @param string $path  The path to store the file in.
  341.      * @param string $name  The filename to use.
  342.      *
  343.      * @return mixed  True on success or a PEAR_Error object on failure.
  344.      */
  345.     function deleteFile($path$name)
  346.     {
  347.         $res $this->_checkQuotaDelete($path$name);
  348.         if (is_a($res'PEAR_Error')) {
  349.             return $res;
  350.         }
  351.  
  352.         if (!@unlink($this->_getNativePath($path$name))) {
  353.             return PEAR::raiseError(_("Unable to delete VFS file."));
  354.         }
  355.  
  356.         return true;
  357.     }
  358.  
  359.     /**
  360.      * Delete a folder from the VFS.
  361.      *
  362.      * @param string $path        The path to delete the folder from.
  363.      * @param string $name        The foldername to use.
  364.      * @param boolean $recursive  Force a recursive delete?
  365.      *
  366.      * @return mixed True on success or a PEAR_Error object on failure.
  367.      */
  368.     function deleteFolder($path$name$recursive = false)
  369.     {
  370.         if ($recursive{
  371.             $result $this->emptyFolder($path '/' $name);
  372.             if (is_a($result'PEAR_Error')) {
  373.                 return $result;
  374.             }
  375.         else {
  376.             $list $this->listFolder($path '/' $name);
  377.             if (is_a($list'PEAR_Error')) {
  378.                 return $list;
  379.             }
  380.             if (count($list)) {
  381.                 return PEAR::raiseError(sprintf(_("Unable to delete %s, the directory is not empty"),
  382.                                                 $path '/' $name));
  383.             }
  384.         }
  385.  
  386.         if (!@rmdir($this->_getNativePath($path$name))) {
  387.             return PEAR::raiseError(_("Unable to delete VFS directory."));
  388.         }
  389.  
  390.         return true;
  391.     }
  392.  
  393.     /**
  394.      * Creates a folder on the VFS.
  395.      *
  396.      * @param string $path  The path to create the folder in.
  397.      * @param string $name  The foldername to use.
  398.      *
  399.      * @return mixed  True on success or a PEAR_Error object on failure.
  400.      */
  401.     function createFolder($path$name)
  402.     {
  403.         if (!@mkdir($this->_getNativePath($path$name))) {
  404.             return PEAR::raiseError(_("Unable to create VFS directory."));
  405.         }
  406.  
  407.         return true;
  408.     }
  409.  
  410.     /**
  411.      * Check if a given pathname is a folder.
  412.      *
  413.      * @param string $path  The path to the folder.
  414.      * @param string $name  The file/folder name.
  415.      *
  416.      * @return boolean  True if it is a folder, false otherwise.
  417.      */
  418.     function isFolder($path$name)
  419.     {
  420.         return @is_dir($this->_getNativePath($path$name));
  421.     }
  422.  
  423.     /**
  424.      * Changes permissions for an item in the VFS.
  425.      *
  426.      * @param string $path         The path of directory of the item.
  427.      * @param string $name         The name of the item.
  428.      * @param integer $permission  The octal value of the new permission.
  429.      *
  430.      * @return mixed  True on success or a PEAR_Error object on failure.
  431.      */
  432.     function changePermissions($path$name$permission)
  433.     {
  434.         if (!@chmod($this->_getNativePath($path$name)$permission)) {
  435.             return PEAR::raiseError(sprintf(_("Unable to change permission for VFS file %s/%s.")$path$name));
  436.         }
  437.  
  438.         return true;
  439.     }
  440.  
  441.     /**
  442.      * Return a list of the contents of a folder.
  443.      *
  444.      * @param string $path       The path of the directory.
  445.      * @param mixed $filter      String/hash to filter file/dirname on.
  446.      * @param boolean $dotfiles  Show dotfiles?
  447.      * @param boolean $dironly   Show only directories?
  448.      *
  449.      * @return array  File list on success, PEAR_Error on error.
  450.      */
  451.     function _listFolder($path$filter = null$dotfiles = true,
  452.                          $dironly = false)
  453.     {
  454.         $files = array();
  455.         $path = isset($path$this->_getNativePath($path$this->_getNativePath();
  456.  
  457.         if (!@is_dir($path)) {
  458.             return PEAR::raiseError(_("Not a directory"));
  459.         }
  460.  
  461.         if (!@chdir($path)) {
  462.             return PEAR::raiseError(_("Unable to access VFS directory."));
  463.         }
  464.  
  465.         $handle opendir($path);
  466.         while (($entry readdir($handle)) !== false{
  467.             // Filter out '.' and '..' entries.
  468.             if ($entry == '.' || $entry == '..'{
  469.                 continue;
  470.             }
  471.  
  472.             // Filter out dotfiles if they aren't wanted.
  473.             if (!$dotfiles && substr($entry01== '.'{
  474.                 continue;
  475.             }
  476.  
  477.             // File name
  478.             $file['name'$entry;
  479.  
  480.             // Unix style file permissions
  481.             $file['perms'$this->_getUnixPerms(fileperms($entry));
  482.  
  483.             // Owner
  484.             $file['owner'fileowner($entry);
  485.             if (function_exists('posix_getpwuid')) {
  486.                 $owner posix_getpwuid($file['owner']);
  487.                 $file['owner'$owner['name'];
  488.             }
  489.  
  490.             // Group
  491.             $file['group'filegroup($entry);
  492.             if (function_exists('posix_getgrgid')) {
  493.                 if (PHP_VERSION != '5.2.1'{
  494.                     $group posix_getgrgid($file['group']);
  495.                     $file['group'$group['name'];
  496.                 }
  497.             }
  498.  
  499.             // Size
  500.             $file['size'filesize($entry);
  501.  
  502.             // Date
  503.             $file['date'filemtime($entry);
  504.  
  505.             // Type
  506.             if (@is_dir($entry&& !is_link($entry)) {
  507.                 $file['perms''d' $file['perms'];
  508.                 $file['type''**dir';
  509.                 $file['size'= -1;
  510.             elseif (is_link($entry)) {
  511.                 $file['perms''l' $file['perms'];
  512.                 $file['type''**sym';
  513.                 $file['link'readlink($entry);
  514.                 $file['linktype''**none';
  515.                 if (file_exists($file['link'])) {
  516.                     if (is_dir($file['link'])) {
  517.                         $file['linktype''**dir';
  518.                     elseif (is_link($file['link'])) {
  519.                         $file['linktype''**sym';
  520.                     elseif (is_file($file['link'])) {
  521.                         $ext explode('.'$file['link']);
  522.                         if (!(count($ext== 1 || ($ext[0=== '' && count($ext== 2))) {
  523.                             $file['linktype'VFS::strtolower($ext[count($ext- 1]);
  524.                         }
  525.                     }
  526.                 else {
  527.                     $file['linktype''**broken';
  528.                 }
  529.             elseif (is_file($entry)) {
  530.                 $file['perms''-' $file['perms'];
  531.                 $ext explode('.'$entry);
  532.  
  533.                 if (count($ext== 1 || (substr($file['name']01=== '.' && count($ext== 2)) {
  534.                     $file['type''**none';
  535.                 else {
  536.                     $file['type'VFS::strtolower($ext[count($ext- 1]);
  537.                 }
  538.             else {
  539.                 $file['type''**none';
  540.                 if ((fileperms($entry0xC000== 0xC000{
  541.                     $file['perms''s' $file['perms'];
  542.                 elseif ((fileperms($entry0x6000== 0x6000{
  543.                     $file['perms''b' $file['perms'];
  544.                 elseif ((fileperms($entry0x2000== 0x2000{
  545.                     $file['perms''c' $file['perms'];
  546.                 elseif ((fileperms($entry0x1000== 0x1000{
  547.                     $file['perms''p' $file['perms'];
  548.                 else {
  549.                     $file['perms''?' $file['perms'];
  550.                 }
  551.             }
  552.  
  553.             // Filtering.
  554.             if ($this->_filterMatch($filter$file['name'])) {
  555.                 unset($file);
  556.                 continue;
  557.             }
  558.             if ($dironly && $file['type'!== '**dir'{
  559.                 unset($file);
  560.                 continue;
  561.             }
  562.  
  563.             $files[$file['name']] $file;
  564.             unset($file);
  565.         }
  566.  
  567.         return $files;
  568.     }
  569.  
  570.     /**
  571.      * Returns a sorted list of folders in specified directory.
  572.      *
  573.      * @param string $path         The path of the directory to get the
  574.      *                              directory list for.
  575.      * @param mixed $filter        Hash of items to filter based on folderlist.
  576.      * @param boolean $dotfolders  Include dotfolders?
  577.      *
  578.      * @return mixed  Folder list on success or a PEAR_Error object on failure.
  579.      */
  580.     function listFolders($path ''$filter = null$dotfolders = true)
  581.     {
  582.         $conn $this->_connect();
  583.         if (is_a($conn'PEAR_Error')) {
  584.             return $conn;
  585.         }
  586.  
  587.         $folders = array();
  588.         $folders[dirname($path)= array('val' => dirname($path),
  589.                                          'abbrev' => '..',
  590.                                          'label' => '..');
  591.  
  592.         $folderList $this->listFolder($pathnull$dotfolderstrue);
  593.         if (is_a($folderList'PEAR_Error')) {
  594.             return $folderList;
  595.         }
  596.  
  597.         foreach ($folderList as $name => $files{
  598.             $folders[$name= array('val' => $path '/' $files['name'],
  599.                                     'abbrev' => $files['name'],
  600.                                     'label' => $path '/' $files['name']);
  601.         }
  602.  
  603.         ksort($folders);
  604.  
  605.         return $folders;
  606.     }
  607.  
  608.     /**
  609.      * Return Unix style perms.
  610.      *
  611.      * @access private
  612.      *
  613.      * @param integer $perms  The permissions to set.
  614.      *
  615.      * @return string  Unix style perms.
  616.      */
  617.     function _getUnixPerms($perms)
  618.     {
  619.         // Determine permissions
  620.         $owner['read']    ($perms 00400'r' '-';
  621.         $owner['write']   ($perms 00200'w' '-';
  622.         $owner['execute'($perms 00100'x' '-';
  623.         $group['read']    ($perms 00040'r' '-';
  624.         $group['write']   ($perms 00020'w' '-';
  625.         $group['execute'($perms 00010'x' '-';
  626.         $world['read']    ($perms 00004'r' '-';
  627.         $world['write']   ($perms 00002'w' '-';
  628.         $world['execute'($perms 00001'x' '-';
  629.  
  630.         // Adjust for SUID, SGID and sticky bit
  631.         if ($perms 0x800{
  632.             $owner['execute'($owner['execute'== 'x''s' 'S';
  633.         }
  634.         if ($perms 0x400{
  635.             $group['execute'($group['execute'== 'x''s' 'S';
  636.         }
  637.         if ($perms 0x200{
  638.             $world['execute'($world['execute'== 'x''t' 'T';
  639.         }
  640.  
  641.         $unixPerms $owner['read'$owner['write'$owner['execute'.
  642.                      $group['read'$group['write'$group['execute'.
  643.                      $world['read'$world['write'$world['execute'];
  644.  
  645.         return $unixPerms;
  646.     }
  647.  
  648.     /**
  649.      * Rename a file or folder in the VFS.
  650.      *
  651.      * @param string $oldpath  The old path to the file.
  652.      * @param string $oldname  The old filename.
  653.      * @param string $newpath  The new path of the file.
  654.      * @param string $newname  The new filename.
  655.      *
  656.      * @return mixed  True on success or a PEAR_Error object on failure.
  657.      */
  658.     function rename($oldpath$oldname$newpath$newname)
  659.     {
  660.         if (!@is_dir($this->_getNativePath($newpath))) {
  661.             if (is_a($res $this->autocreatePath($newpath)'PEAR_Error')) {
  662.                 return $res;
  663.             }
  664.         }
  665.  
  666.         if (!@rename($this->_getNativePath($oldpath$oldname),
  667.                      $this->_getNativePath($newpath$newname))) {
  668.             return PEAR::raiseError(sprintf(_("Unable to rename VFS file %s/%s.")$oldpath$oldname));
  669.         }
  670.  
  671.         return true;
  672.     }
  673.  
  674.     /**
  675.      * Return a full filename on the native filesystem, from a VFS
  676.      * path and name.
  677.      *
  678.      * @access private
  679.      *
  680.      * @param string $path  The VFS file path.
  681.      * @param string $name  The VFS filename.
  682.      *
  683.      * @return string  The full native filename.
  684.      */
  685.     function _getNativePath($path ''$name '')
  686.     {
  687.         $name basename($name);
  688.         if (strlen($name)) {
  689.             $name str_replace('..'''$name);
  690.             if (substr($name01!= '/'{
  691.                 $name '/' $name;
  692.             }
  693.         }
  694.  
  695.         if (strlen($path)) {
  696.             if (isset($this->_params['home']&&
  697.                 preg_match('|^~/?(.*)$|'$path$matches)) {
  698.                 $path $this->_params['home''/' $matches[1];
  699.             }
  700.  
  701.             $path str_replace('..'''$path);
  702.             if (substr($path01== '/'{
  703.                 return $this->_params['vfsroot'$path $name;
  704.             else {
  705.                 return $this->_params['vfsroot''/' $path $name;
  706.             }
  707.         else {
  708.             return $this->_params['vfsroot'$name;
  709.         }
  710.     }
  711.  
  712.     /**
  713.      * Stub to check if we have a valid connection. Makes sure that
  714.      * the vfsroot is readable.
  715.      *
  716.      * @access private
  717.      *
  718.      * @return mixed  True if vfsroot is readable, PEAR_Error if it isn't.
  719.      */
  720.     function _connect()
  721.     {
  722.         if ((@is_dir($this->_params['vfsroot']&&
  723.              is_readable($this->_params['vfsroot'])) ||
  724.             @mkdir($this->_params['vfsroot'])) {
  725.             return true;
  726.         else {
  727.             return PEAR::raiseError(_("Unable to read the vfsroot directory."));
  728.         }
  729.     }
  730.  
  731. }

Documentation generated on Mon, 11 Mar 2019 15:16:26 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.