[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/includes/ -> class-wp-filesystem-base.php (source)

   1  <?php
   2  /**
   3   * Base WordPress Filesystem
   4   *
   5   * @package WordPress
   6   * @subpackage Filesystem
   7   */
   8  
   9  /**
  10   * Base WordPress Filesystem class which Filesystem implementations extend.
  11   *
  12   * @since 2.5.0
  13   */
  14  class WP_Filesystem_Base {
  15  
  16      /**
  17       * Whether to display debug data for the connection.
  18       *
  19       * @since 2.5.0
  20       * @var bool
  21       */
  22      public $verbose = false;
  23  
  24      /**
  25       * Cached list of local filepaths to mapped remote filepaths.
  26       *
  27       * @since 2.7.0
  28       * @var array
  29       */
  30      public $cache = array();
  31  
  32      /**
  33       * The Access method of the current connection, Set automatically.
  34       *
  35       * @since 2.5.0
  36       * @var string
  37       */
  38      public $method = '';
  39  
  40      /**
  41       * @var WP_Error
  42       */
  43      public $errors = null;
  44  
  45      /**
  46       */
  47      public $options = array();
  48  
  49      /**
  50       * Returns the path on the remote filesystem of ABSPATH.
  51       *
  52       * @since 2.7.0
  53       *
  54       * @return string The location of the remote path.
  55       */
  56  	public function abspath() {
  57          $folder = $this->find_folder( ABSPATH );
  58          // Perhaps the FTP folder is rooted at the WordPress install.
  59          // Check for wp-includes folder in root. Could have some false positives, but rare.
  60          if ( ! $folder && $this->is_dir( '/' . WPINC ) ) {
  61              $folder = '/';
  62          }
  63          return $folder;
  64      }
  65  
  66      /**
  67       * Returns the path on the remote filesystem of WP_CONTENT_DIR.
  68       *
  69       * @since 2.7.0
  70       *
  71       * @return string The location of the remote path.
  72       */
  73  	public function wp_content_dir() {
  74          return $this->find_folder( WP_CONTENT_DIR );
  75      }
  76  
  77      /**
  78       * Returns the path on the remote filesystem of WP_PLUGIN_DIR.
  79       *
  80       * @since 2.7.0
  81       *
  82       * @return string The location of the remote path.
  83       */
  84  	public function wp_plugins_dir() {
  85          return $this->find_folder( WP_PLUGIN_DIR );
  86      }
  87  
  88      /**
  89       * Returns the path on the remote filesystem of the Themes Directory.
  90       *
  91       * @since 2.7.0
  92       *
  93       * @param string|false $theme Optional. The theme stylesheet or template for the directory.
  94       *                            Default false.
  95       * @return string The location of the remote path.
  96       */
  97  	public function wp_themes_dir( $theme = false ) {
  98          $theme_root = get_theme_root( $theme );
  99  
 100          // Account for relative theme roots.
 101          if ( '/themes' == $theme_root || ! is_dir( $theme_root ) ) {
 102              $theme_root = WP_CONTENT_DIR . $theme_root;
 103          }
 104  
 105          return $this->find_folder( $theme_root );
 106      }
 107  
 108      /**
 109       * Returns the path on the remote filesystem of WP_LANG_DIR.
 110       *
 111       * @since 3.2.0
 112       *
 113       * @return string The location of the remote path.
 114       */
 115  	public function wp_lang_dir() {
 116          return $this->find_folder( WP_LANG_DIR );
 117      }
 118  
 119      /**
 120       * Locates a folder on the remote filesystem.
 121       *
 122       * @since 2.5.0
 123       * @deprecated 2.7.0 use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() instead.
 124       * @see WP_Filesystem::abspath()
 125       * @see WP_Filesystem::wp_content_dir()
 126       * @see WP_Filesystem::wp_plugins_dir()
 127       * @see WP_Filesystem::wp_themes_dir()
 128       * @see WP_Filesystem::wp_lang_dir()
 129       *
 130       * @param string $base The folder to start searching from.
 131       * @param bool   $echo True to display debug information.
 132       *                     Default false.
 133       * @return string The location of the remote path.
 134       */
 135  	public function find_base_dir( $base = '.', $echo = false ) {
 136          _deprecated_function( __FUNCTION__, '2.7.0', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
 137          $this->verbose = $echo;
 138          return $this->abspath();
 139      }
 140  
 141      /**
 142       * Locates a folder on the remote filesystem.
 143       *
 144       * @since 2.5.0
 145       * @deprecated 2.7.0 use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead.
 146       * @see WP_Filesystem::abspath()
 147       * @see WP_Filesystem::wp_content_dir()
 148       * @see WP_Filesystem::wp_plugins_dir()
 149       * @see WP_Filesystem::wp_themes_dir()
 150       * @see WP_Filesystem::wp_lang_dir()
 151       *
 152       * @param string $base The folder to start searching from.
 153       * @param bool   $echo True to display debug information.
 154       * @return string The location of the remote path.
 155       */
 156  	public function get_base_dir( $base = '.', $echo = false ) {
 157          _deprecated_function( __FUNCTION__, '2.7.0', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
 158          $this->verbose = $echo;
 159          return $this->abspath();
 160      }
 161  
 162      /**
 163       * Locates a folder on the remote filesystem.
 164       *
 165       * Assumes that on Windows systems, Stripping off the Drive
 166       * letter is OK Sanitizes \\ to / in Windows filepaths.
 167       *
 168       * @since 2.7.0
 169       *
 170       * @param string $folder the folder to locate.
 171       * @return string|false The location of the remote path, false on failure.
 172       */
 173  	public function find_folder( $folder ) {
 174          if ( isset( $this->cache[ $folder ] ) ) {
 175              return $this->cache[ $folder ];
 176          }
 177  
 178          if ( stripos( $this->method, 'ftp' ) !== false ) {
 179              $constant_overrides = array(
 180                  'FTP_BASE'        => ABSPATH,
 181                  'FTP_CONTENT_DIR' => WP_CONTENT_DIR,
 182                  'FTP_PLUGIN_DIR'  => WP_PLUGIN_DIR,
 183                  'FTP_LANG_DIR'    => WP_LANG_DIR,
 184              );
 185  
 186              // Direct matches ( folder = CONSTANT/ ).
 187              foreach ( $constant_overrides as $constant => $dir ) {
 188                  if ( ! defined( $constant ) ) {
 189                      continue;
 190                  }
 191                  if ( $folder === $dir ) {
 192                      return trailingslashit( constant( $constant ) );
 193                  }
 194              }
 195  
 196              // Prefix matches ( folder = CONSTANT/subdir ),
 197              foreach ( $constant_overrides as $constant => $dir ) {
 198                  if ( ! defined( $constant ) ) {
 199                      continue;
 200                  }
 201                  if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir.
 202                      $potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder );
 203                      $potential_folder = trailingslashit( $potential_folder );
 204  
 205                      if ( $this->is_dir( $potential_folder ) ) {
 206                          $this->cache[ $folder ] = $potential_folder;
 207                          return $potential_folder;
 208                      }
 209                  }
 210              }
 211          } elseif ( 'direct' == $this->method ) {
 212              $folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation.
 213              return trailingslashit( $folder );
 214          }
 215  
 216          $folder = preg_replace( '|^([a-z]{1}):|i', '', $folder ); // Strip out Windows drive letter if it's there.
 217          $folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation.
 218  
 219          if ( isset( $this->cache[ $folder ] ) ) {
 220              return $this->cache[ $folder ];
 221          }
 222  
 223          if ( $this->exists( $folder ) ) { // Folder exists at that absolute path.
 224              $folder                 = trailingslashit( $folder );
 225              $this->cache[ $folder ] = $folder;
 226              return $folder;
 227          }
 228          $return = $this->search_for_folder( $folder );
 229          if ( $return ) {
 230              $this->cache[ $folder ] = $return;
 231          }
 232          return $return;
 233      }
 234  
 235      /**
 236       * Locates a folder on the remote filesystem.
 237       *
 238       * Expects Windows sanitized path.
 239       *
 240       * @since 2.7.0
 241       *
 242       * @param string $folder The folder to locate.
 243       * @param string $base   The folder to start searching from.
 244       * @param bool   $loop   If the function has recursed. Internal use only.
 245       * @return string|false The location of the remote path, false to cease looping.
 246       */
 247  	public function search_for_folder( $folder, $base = '.', $loop = false ) {
 248          if ( empty( $base ) || '.' == $base ) {
 249              $base = trailingslashit( $this->cwd() );
 250          }
 251  
 252          $folder = untrailingslashit( $folder );
 253  
 254          if ( $this->verbose ) {
 255              /* translators: 1: Folder to locate, 2: Folder to start searching from. */
 256              printf( "\n" . __( 'Looking for %1$s in %2$s' ) . "<br/>\n", $folder, $base );
 257          }
 258  
 259          $folder_parts     = explode( '/', $folder );
 260          $folder_part_keys = array_keys( $folder_parts );
 261          $last_index       = array_pop( $folder_part_keys );
 262          $last_path        = $folder_parts[ $last_index ];
 263  
 264          $files = $this->dirlist( $base );
 265  
 266          foreach ( $folder_parts as $index => $key ) {
 267              if ( $index == $last_index ) {
 268                  continue; // We want this to be caught by the next code block.
 269              }
 270  
 271              /*
 272               * Working from /home/ to /user/ to /wordpress/ see if that file exists within
 273               * the current folder, If it's found, change into it and follow through looking
 274               * for it. If it can't find WordPress down that route, it'll continue onto the next
 275               * folder level, and see if that matches, and so on. If it reaches the end, and still
 276               * can't find it, it'll return false for the entire function.
 277               */
 278              if ( isset( $files[ $key ] ) ) {
 279  
 280                  // Let's try that folder:
 281                  $newdir = trailingslashit( path_join( $base, $key ) );
 282                  if ( $this->verbose ) {
 283                      /* translators: %s: Directory name. */
 284                      printf( "\n" . __( 'Changing to %s' ) . "<br/>\n", $newdir );
 285                  }
 286  
 287                  // Only search for the remaining path tokens in the directory, not the full path again.
 288                  $newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) );
 289                  $ret       = $this->search_for_folder( $newfolder, $newdir, $loop );
 290                  if ( $ret ) {
 291                      return $ret;
 292                  }
 293              }
 294          }
 295  
 296          // Only check this as a last resort, to prevent locating the incorrect install.
 297          // All above procedures will fail quickly if this is the right branch to take.
 298          if ( isset( $files[ $last_path ] ) ) {
 299              if ( $this->verbose ) {
 300                  /* translators: %s: Directory name. */
 301                  printf( "\n" . __( 'Found %s' ) . "<br/>\n", $base . $last_path );
 302              }
 303              return trailingslashit( $base . $last_path );
 304          }
 305  
 306          // Prevent this function from looping again.
 307          // No need to proceed if we've just searched in `/`.
 308          if ( $loop || '/' == $base ) {
 309              return false;
 310          }
 311  
 312          // As an extra last resort, Change back to / if the folder wasn't found.
 313          // This comes into effect when the CWD is /home/user/ but WP is at /var/www/....
 314          return $this->search_for_folder( $folder, '/', true );
 315  
 316      }
 317  
 318      /**
 319       * Returns the *nix-style file permissions for a file.
 320       *
 321       * From the PHP documentation page for fileperms().
 322       *
 323       * @link https://www.php.net/manual/en/function.fileperms.php
 324       *
 325       * @since 2.5.0
 326       *
 327       * @param string $file String filename.
 328       * @return string The *nix-style representation of permissions.
 329       */
 330  	public function gethchmod( $file ) {
 331          $perms = intval( $this->getchmod( $file ), 8 );
 332          if ( ( $perms & 0xC000 ) == 0xC000 ) { // Socket.
 333              $info = 's';
 334          } elseif ( ( $perms & 0xA000 ) == 0xA000 ) { // Symbolic Link.
 335              $info = 'l';
 336          } elseif ( ( $perms & 0x8000 ) == 0x8000 ) { // Regular.
 337              $info = '-';
 338          } elseif ( ( $perms & 0x6000 ) == 0x6000 ) { // Block special.
 339              $info = 'b';
 340          } elseif ( ( $perms & 0x4000 ) == 0x4000 ) { // Directory.
 341              $info = 'd';
 342          } elseif ( ( $perms & 0x2000 ) == 0x2000 ) { // Character special.
 343              $info = 'c';
 344          } elseif ( ( $perms & 0x1000 ) == 0x1000 ) { // FIFO pipe.
 345              $info = 'p';
 346          } else { // Unknown.
 347              $info = 'u';
 348          }
 349  
 350          // Owner.
 351          $info .= ( ( $perms & 0x0100 ) ? 'r' : '-' );
 352          $info .= ( ( $perms & 0x0080 ) ? 'w' : '-' );
 353          $info .= ( ( $perms & 0x0040 ) ?
 354                      ( ( $perms & 0x0800 ) ? 's' : 'x' ) :
 355                      ( ( $perms & 0x0800 ) ? 'S' : '-' ) );
 356  
 357          // Group.
 358          $info .= ( ( $perms & 0x0020 ) ? 'r' : '-' );
 359          $info .= ( ( $perms & 0x0010 ) ? 'w' : '-' );
 360          $info .= ( ( $perms & 0x0008 ) ?
 361                      ( ( $perms & 0x0400 ) ? 's' : 'x' ) :
 362                      ( ( $perms & 0x0400 ) ? 'S' : '-' ) );
 363  
 364          // World.
 365          $info .= ( ( $perms & 0x0004 ) ? 'r' : '-' );
 366          $info .= ( ( $perms & 0x0002 ) ? 'w' : '-' );
 367          $info .= ( ( $perms & 0x0001 ) ?
 368                      ( ( $perms & 0x0200 ) ? 't' : 'x' ) :
 369                      ( ( $perms & 0x0200 ) ? 'T' : '-' ) );
 370          return $info;
 371      }
 372  
 373      /**
 374       * Gets the permissions of the specified file or filepath in their octal format.
 375       *
 376       * @since 2.5.0
 377       *
 378       * @param string $file Path to the file.
 379       * @return string Mode of the file (the last 3 digits).
 380       */
 381  	public function getchmod( $file ) {
 382          return '777';
 383      }
 384  
 385      /**
 386       * Converts *nix-style file permissions to a octal number.
 387       *
 388       * Converts '-rw-r--r--' to 0644
 389       * From "info at rvgate dot nl"'s comment on the PHP documentation for chmod()
 390       *
 391       * @link https://www.php.net/manual/en/function.chmod.php#49614
 392       *
 393       * @since 2.5.0
 394       *
 395       * @param string $mode string The *nix-style file permission.
 396       * @return int octal representation
 397       */
 398  	public function getnumchmodfromh( $mode ) {
 399          $realmode = '';
 400          $legal    = array( '', 'w', 'r', 'x', '-' );
 401          $attarray = preg_split( '//', $mode );
 402  
 403          for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) {
 404              $key = array_search( $attarray[ $i ], $legal );
 405              if ( $key ) {
 406                  $realmode .= $legal[ $key ];
 407              }
 408          }
 409  
 410          $mode  = str_pad( $realmode, 10, '-', STR_PAD_LEFT );
 411          $trans = array(
 412              '-' => '0',
 413              'r' => '4',
 414              'w' => '2',
 415              'x' => '1',
 416          );
 417          $mode  = strtr( $mode, $trans );
 418  
 419          $newmode  = $mode[0];
 420          $newmode .= $mode[1] + $mode[2] + $mode[3];
 421          $newmode .= $mode[4] + $mode[5] + $mode[6];
 422          $newmode .= $mode[7] + $mode[8] + $mode[9];
 423          return $newmode;
 424      }
 425  
 426      /**
 427       * Determines if the string provided contains binary characters.
 428       *
 429       * @since 2.7.0
 430       *
 431       * @param string $text String to test against.
 432       * @return bool True if string is binary, false otherwise.
 433       */
 434  	public function is_binary( $text ) {
 435          return (bool) preg_match( '|[^\x20-\x7E]|', $text ); // chr(32)..chr(127)
 436      }
 437  
 438      /**
 439       * Changes the owner of a file or directory.
 440       *
 441       * Default behavior is to do nothing, override this in your subclass, if desired.
 442       *
 443       * @since 2.5.0
 444       *
 445       * @param string     $file      Path to the file or directory.
 446       * @param string|int $owner     A user name or number.
 447       * @param bool       $recursive Optional. If set to true, changes file owner recursively.
 448       *                              Default false.
 449       * @return bool True on success, false on failure.
 450       */
 451  	public function chown( $file, $owner, $recursive = false ) {
 452          return false;
 453      }
 454  
 455      /**
 456       * Connects filesystem.
 457       *
 458       * @since 2.5.0
 459       * @abstract
 460       *
 461       * @return bool True on success, false on failure (always true for WP_Filesystem_Direct).
 462       */
 463  	public function connect() {
 464          return true;
 465      }
 466  
 467      /**
 468       * Reads entire file into a string.
 469       *
 470       * @since 2.5.0
 471       * @abstract
 472       *
 473       * @param string $file Name of the file to read.
 474       * @return string|false Read data on success, false on failure.
 475       */
 476  	public function get_contents( $file ) {
 477          return false;
 478      }
 479  
 480      /**
 481       * Reads entire file into an array.
 482       *
 483       * @since 2.5.0
 484       * @abstract
 485       *
 486       * @param string $file Path to the file.
 487       * @return array|false File contents in an array on success, false on failure.
 488       */
 489  	public function get_contents_array( $file ) {
 490          return false;
 491      }
 492  
 493      /**
 494       * Writes a string to a file.
 495       *
 496       * @since 2.5.0
 497       * @abstract
 498       *
 499       * @param string    $file     Remote path to the file where to write the data.
 500       * @param string    $contents The data to write.
 501       * @param int|false $mode     Optional. The file permissions as octal number, usually 0644.
 502       *                            Default false.
 503       * @return bool True on success, false on failure.
 504       */
 505  	public function put_contents( $file, $contents, $mode = false ) {
 506          return false;
 507      }
 508  
 509      /**
 510       * Gets the current working directory.
 511       *
 512       * @since 2.5.0
 513       * @abstract
 514       *
 515       * @return string|false The current working directory on success, false on failure.
 516       */
 517  	public function cwd() {
 518          return false;
 519      }
 520  
 521      /**
 522       * Changes current directory.
 523       *
 524       * @since 2.5.0
 525       * @abstract
 526       *
 527       * @param string $dir The new current directory.
 528       * @return bool True on success, false on failure.
 529       */
 530  	public function chdir( $dir ) {
 531          return false;
 532      }
 533  
 534      /**
 535       * Changes the file group.
 536       *
 537       * @since 2.5.0
 538       * @abstract
 539       *
 540       * @param string     $file      Path to the file.
 541       * @param string|int $group     A group name or number.
 542       * @param bool       $recursive Optional. If set to true, changes file group recursively.
 543       *                              Default false.
 544       * @return bool True on success, false on failure.
 545       */
 546  	public function chgrp( $file, $group, $recursive = false ) {
 547          return false;
 548      }
 549  
 550      /**
 551       * Changes filesystem permissions.
 552       *
 553       * @since 2.5.0
 554       * @abstract
 555       *
 556       * @param string    $file      Path to the file.
 557       * @param int|false $mode      Optional. The permissions as octal number, usually 0644 for files,
 558       *                             0755 for directories. Default false.
 559       * @param bool      $recursive Optional. If set to true, changes file permissions recursively.
 560       *                             Default false.
 561       * @return bool True on success, false on failure.
 562       */
 563  	public function chmod( $file, $mode = false, $recursive = false ) {
 564          return false;
 565      }
 566  
 567      /**
 568       * Gets the file owner.
 569       *
 570       * @since 2.5.0
 571       * @abstract
 572       *
 573       * @param string $file Path to the file.
 574       * @return string|false Username of the owner on success, false on failure.
 575       */
 576  	public function owner( $file ) {
 577          return false;
 578      }
 579  
 580      /**
 581       * Gets the file's group.
 582       *
 583       * @since 2.5.0
 584       * @abstract
 585       *
 586       * @param string $file Path to the file.
 587       * @return string|false The group on success, false on failure.
 588       */
 589  	public function group( $file ) {
 590          return false;
 591      }
 592  
 593      /**
 594       * Copies a file.
 595       *
 596       * @since 2.5.0
 597       * @abstract
 598       *
 599       * @param string    $source      Path to the source file.
 600       * @param string    $destination Path to the destination file.
 601       * @param bool      $overwrite   Optional. Whether to overwrite the destination file if it exists.
 602       *                               Default false.
 603       * @param int|false $mode        Optional. The permissions as octal number, usually 0644 for files,
 604       *                               0755 for dirs. Default false.
 605       * @return bool True on success, false on failure.
 606       */
 607  	public function copy( $source, $destination, $overwrite = false, $mode = false ) {
 608          return false;
 609      }
 610  
 611      /**
 612       * Moves a file.
 613       *
 614       * @since 2.5.0
 615       * @abstract
 616       *
 617       * @param string $source      Path to the source file.
 618       * @param string $destination Path to the destination file.
 619       * @param bool   $overwrite   Optional. Whether to overwrite the destination file if it exists.
 620       *                            Default false.
 621       * @return bool True on success, false on failure.
 622       */
 623  	public function move( $source, $destination, $overwrite = false ) {
 624          return false;
 625      }
 626  
 627      /**
 628       * Deletes a file or directory.
 629       *
 630       * @since 2.5.0
 631       * @abstract
 632       *
 633       * @param string       $file      Path to the file or directory.
 634       * @param bool         $recursive Optional. If set to true, deletes files and folders recursively.
 635       *                                Default false.
 636       * @param string|false $type      Type of resource. 'f' for file, 'd' for directory.
 637       *                                Default false.
 638       * @return bool True on success, false on failure.
 639       */
 640  	public function delete( $file, $recursive = false, $type = false ) {
 641          return false;
 642      }
 643  
 644      /**
 645       * Checks if a file or directory exists.
 646       *
 647       * @since 2.5.0
 648       * @abstract
 649       *
 650       * @param string $file Path to file or directory.
 651       * @return bool Whether $file exists or not.
 652       */
 653  	public function exists( $file ) {
 654          return false;
 655      }
 656  
 657      /**
 658       * Checks if resource is a file.
 659       *
 660       * @since 2.5.0
 661       * @abstract
 662       *
 663       * @param string $file File path.
 664       * @return bool Whether $file is a file.
 665       */
 666  	public function is_file( $file ) {
 667          return false;
 668      }
 669  
 670      /**
 671       * Checks if resource is a directory.
 672       *
 673       * @since 2.5.0
 674       * @abstract
 675       *
 676       * @param string $path Directory path.
 677       * @return bool Whether $path is a directory.
 678       */
 679  	public function is_dir( $path ) {
 680          return false;
 681      }
 682  
 683      /**
 684       * Checks if a file is readable.
 685       *
 686       * @since 2.5.0
 687       * @abstract
 688       *
 689       * @param string $file Path to file.
 690       * @return bool Whether $file is readable.
 691       */
 692  	public function is_readable( $file ) {
 693          return false;
 694      }
 695  
 696      /**
 697       * Checks if a file or directory is writable.
 698       *
 699       * @since 2.5.0
 700       * @abstract
 701       *
 702       * @param string $file Path to file or directory.
 703       * @return bool Whether $file is writable.
 704       */
 705  	public function is_writable( $file ) {
 706          return false;
 707      }
 708  
 709      /**
 710       * Gets the file's last access time.
 711       *
 712       * @since 2.5.0
 713       * @abstract
 714       *
 715       * @param string $file Path to file.
 716       * @return int|false Unix timestamp representing last access time, false on failure.
 717       */
 718  	public function atime( $file ) {
 719          return false;
 720      }
 721  
 722      /**
 723       * Gets the file modification time.
 724       *
 725       * @since 2.5.0
 726       * @abstract
 727       *
 728       * @param string $file Path to file.
 729       * @return int|false Unix timestamp representing modification time, false on failure.
 730       */
 731  	public function mtime( $file ) {
 732          return false;
 733      }
 734  
 735      /**
 736       * Gets the file size (in bytes).
 737       *
 738       * @since 2.5.0
 739       * @abstract
 740       *
 741       * @param string $file Path to file.
 742       * @return int|false Size of the file in bytes on success, false on failure.
 743       */
 744  	public function size( $file ) {
 745          return false;
 746      }
 747  
 748      /**
 749       * Sets the access and modification times of a file.
 750       *
 751       * Note: If $file doesn't exist, it will be created.
 752       *
 753       * @since 2.5.0
 754       * @abstract
 755       *
 756       * @param string $file  Path to file.
 757       * @param int    $time  Optional. Modified time to set for file.
 758       *                      Default 0.
 759       * @param int    $atime Optional. Access time to set for file.
 760       *                      Default 0.
 761       * @return bool True on success, false on failure.
 762       */
 763  	public function touch( $file, $time = 0, $atime = 0 ) {
 764          return false;
 765      }
 766  
 767      /**
 768       * Creates a directory.
 769       *
 770       * @since 2.5.0
 771       * @abstract
 772       *
 773       * @param string     $path  Path for new directory.
 774       * @param int|false  $chmod Optional. The permissions as octal number (or false to skip chmod).
 775       *                          Default false.
 776       * @param string|int $chown Optional. A user name or number (or false to skip chown).
 777       *                          Default false.
 778       * @param string|int $chgrp Optional. A group name or number (or false to skip chgrp).
 779       *                          Default false.
 780       * @return bool True on success, false on failure.
 781       */
 782  	public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
 783          return false;
 784      }
 785  
 786      /**
 787       * Deletes a directory.
 788       *
 789       * @since 2.5.0
 790       * @abstract
 791       *
 792       * @param string $path      Path to directory.
 793       * @param bool   $recursive Optional. Whether to recursively remove files/directories.
 794       *                          Default false.
 795       * @return bool True on success, false on failure.
 796       */
 797  	public function rmdir( $path, $recursive = false ) {
 798          return false;
 799      }
 800  
 801      /**
 802       * Gets details for files in a directory or a specific file.
 803       *
 804       * @since 2.5.0
 805       * @abstract
 806       *
 807       * @param string $path           Path to directory or file.
 808       * @param bool   $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
 809       *                               Default true.
 810       * @param bool   $recursive      Optional. Whether to recursively include file details in nested directories.
 811       *                               Default false.
 812       * @return array|false {
 813       *     Array of files. False if unable to list directory contents.
 814       *
 815       *     @type string $name        Name of the file or directory.
 816       *     @type string $perms       *nix representation of permissions.
 817       *     @type int    $permsn      Octal representation of permissions.
 818       *     @type string $owner       Owner name or ID.
 819       *     @type int    $size        Size of file in bytes.
 820       *     @type int    $lastmodunix Last modified unix timestamp.
 821       *     @type mixed  $lastmod     Last modified month (3 letter) and day (without leading 0).
 822       *     @type int    $time        Last modified time.
 823       *     @type string $type        Type of resource. 'f' for file, 'd' for directory.
 824       *     @type mixed  $files       If a directory and $recursive is true, contains another array of files.
 825       * }
 826       */
 827  	public function dirlist( $path, $include_hidden = true, $recursive = false ) {
 828          return false;
 829      }
 830  
 831  }


Generated: Sun Apr 5 01:00:03 2020 Cross-referenced by PHPXref 0.7.1