isDirectory example

/** * Copies a directory. * * We need a separate method to make sure the $destination is in the jail. * * @param string $source * The source path. * @param string $destination * The destination path. */
  protected function copyDirectoryJailed($source$destination) {
    if ($this->isDirectory($destination)) {
      $destination = $destination . '/' . \Drupal::service('file_system')->basename($source);
    }
    $this->createDirectory($destination);
    foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $filename => $file) {
      $relative_path = substr($filenamestrlen($source));
      if ($file->isDir()) {
        $this->createDirectory($destination . $relative_path);
      }
      else {
        $this->copyFile($file->getPathName()$destination . $relative_path);
      }
    }
public function isFile($path) {
    return ftp_size($this->connection, $path) != -1;
  }

  /** * {@inheritdoc} */
  public function chmodJailed($path$mode$recursive) {
    if (!ftp_chmod($this->connection, $mode$path)) {
      throw new FileTransferException("Unable to set permissions on %file", 0, ['%file' => $path]);
    }
    if ($this->isDirectory($path) && $recursive) {
      $filelist = @ftp_nlist($this->connection, $path);
      if (!$filelist) {
        // empty directory - returns false         return;
      }
      foreach ($filelist as $file) {
        $this->chmodJailed($file$mode$recursive);
      }
    }
  }

}
Home | Imprint | This part of the site doesn't use cookies.