当前位置: 首页>>代码示例>>PHP>>正文


PHP Net_SFTP::touch方法代码示例

本文整理汇总了PHP中Net_SFTP::touch方法的典型用法代码示例。如果您正苦于以下问题:PHP Net_SFTP::touch方法的具体用法?PHP Net_SFTP::touch怎么用?PHP Net_SFTP::touch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Net_SFTP的用法示例。


在下文中一共展示了Net_SFTP::touch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: stream_open

 /**
  * This method is called immediately after the wrapper is initialized
  *
  * Connects to an SFTP server
  *
  * NOTE: This method is not get called by default for the following functions:
  * dir_opendir(), mkdir(), rename(), rmdir(), stream_metadata(), unlink() and url_stat()
  * So I implemented a call to stream_open() at the beginning of the functions and stream_close() at the end
  *
  * The wrapper will also reuse open connections
  *
  * @param String $path
  * @param String $mode
  * @param Integer $options
  * @param String &$opened_path
  * @return bool
  * @access public
  */
 public function stream_open($path, $mode, $options, &$opened_path)
 {
     $url = parse_url($path);
     $host = $url["host"];
     $port = $url["port"];
     $user = $url["user"];
     $pass = $url["pass"];
     $this->path = $url["path"];
     $connection_uuid = md5($host . $port . $user);
     // Generate a unique ID for the current connection
     if (isset(self::$instances[$connection_uuid])) {
         // Get previously established connection
         $this->sftp = self::$instances[$connection_uuid];
     } else {
         //$context = stream_context_get_options($this->context);
         if (!isset($user) || !isset($pass)) {
             return FALSE;
         }
         // Connection
         $sftp = new Net_SFTP($host, isset($port) ? $port : 22);
         if (!$sftp->login($user, $pass)) {
             return FALSE;
         }
         // Store connection instance
         self::$instances[$connection_uuid] = $sftp;
         // Get current connection
         $this->sftp = $sftp;
     }
     $filesize = $this->sftp->size($this->path);
     if (isset($mode)) {
         $this->mode = preg_replace('#[bt]$#', '', $mode);
     } else {
         $this->mode = 'r';
     }
     switch ($this->mode[0]) {
         case 'r':
             $this->position = 0;
             break;
         case 'w':
             $this->position = 0;
             if ($filesize === FALSE) {
                 $this->sftp->touch($this->path);
             } else {
                 $this->sftp->truncate($this->path, 0);
             }
             break;
         case 'a':
             if ($filesize === FALSE) {
                 $this->position = 0;
                 $this->sftp->touch($this->path);
             } else {
                 $this->position = $filesize;
             }
             break;
         case 'c':
             $this->position = 0;
             if ($filesize === FALSE) {
                 $this->sftp->touch($this->path);
             }
             break;
         default:
             return FALSE;
     }
     if ($options == STREAM_USE_PATH) {
         $opened_path = $this->sftp->pwd();
     }
     return TRUE;
 }
开发者ID:floffel03,项目名称:pydio-core,代码行数:86,代码来源:SFTPPSL_StreamWrapper.php


注:本文中的Net_SFTP::touch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。