コード例 #1
0
 /**
  * Do a Put on Webdav server
  *
  * @param   io.File file
  * @param   string uri, filename or directory
  * @return  peer.http.HttpResponse response object
  * @see     rfc://2518
  */
 public function put($file, $uri = NULL)
 {
     // If no uri or filename is specified, take the original filename
     if ($uri === NULL) {
         $uri = $file->getFilename();
     }
     // Encode uri to handle files/directories containing spaces
     $uri = rawurlencode($uri);
     if (!$file->isOpen()) {
         $file->open(FILE_MODE_READ);
     }
     return $this->getConnection($uri)->put(new RequestData($file->read($file->size())), array(new Header('Content-Type', MimeType::getByFilename($uri))));
 }
コード例 #2
0
 /**
  * Add a file to the Blog
  *
  * @param   &io.File file
  * @return  array url of the file
  */
 public function newMediaObject($file)
 {
     return $this->invoke('metaWeblog.newMediaObject', $this->blogid, $this->username, $this->password, array('name' => $file->getFileName(), 'type' => MimeType::getByFilename($file->getFileName()), 'bits' => Base64::encode(FileUtil::getContents($file))));
 }
コード例 #3
0
 /**
  * Get a file
  *
  * @param   string filename
  * @return  org.webdav.WebdavObject
  * @throws  lang.ElementNotFoundException
  * @throws  org.webdav.OperationNotAllowedException
  */
 public function get($filename, $token = NULL)
 {
     $this->c->debug('FILENAME', $filename);
     $this->c->debug('TOKEN', $token);
     $filename = $this->_normalizePath($filename);
     // check for lock
     $lockinfo = $this->getLockInfo($filename);
     if ($lockinfo and $lockinfo['type'] == 'exclusive' and 'opaquelocktoken:' . $lockinfo['token'] != $token) {
         throw new IllegalArgumentException($filename . ' is locked exclusive');
     }
     if (is_dir($this->base . $filename)) {
         $this->c->debug(get_class($this), '::GET Dir', $filename);
         $f = new Folder($this->base . $filename);
         if (!$f->exists()) {
             throw new ElementNotFoundException($filename . ' not found');
         }
         while ($maxdepth >= 0 && ($entry = $f->getEntry())) {
             $isdir = is_dir($this->base . $filename . '/' . $entry);
             $atime = date('H:i:s  d.m.y', fileatime($this->base . $filename . '/' . $entry));
             if ($isdir) {
                 $flist[0][$entry] .= sprintf('
         <tr>
         <td><a href="%s/">%s</a></td>
         <td>&lt;DIR&gt;</td>
         <td>%s</td>
         <td>&nbsp;&nbsp;</td>
         </tr> 
         ', rawurlencode($entry), $entry, $atime);
             } else {
                 $flist[1][$entry] .= sprintf('
         <tr>
         <td><a href="%s">%s</a></td>
         <td>&nbsp;&nbsp;&nbsp;</td>
         <td>%s</td>
         <td>%s Bytes</td>
         </tr> 
         ', rawurlencode($entry), $entry, $atime, filesize($this->base . $filename . '/' . $entry));
             }
         }
         asort($flist[0]);
         $html = '<table cellpadding=3>' . (strlen($filename) > 2 ? '<tr><td><a href="../">..</a></td><td>&lt;DIR&gt;</tr>' : '') . implode('', $flist[0]);
         asort($flist[1]);
         $flist = $html . implode('', $flist[1]) . '</table>';
         $o = new WebdavObject($f->uri, NULL, strlen($flist), 'text/html', new Date(filectime($f->uri)), new Date(filemtime($f->uri)));
         $o->setData($flist);
         $f->close();
         return $o;
     }
     $this->c->debug(get_class($this), '::GET filename', $filename);
     $this->c->debug(get_class($this), '::GET base', $this->base);
     // Open file and read contents
     // contentype
     if (!file_exists($this->base . $filename)) {
         throw new ElementNotFoundException($filename . ' not found');
     }
     $f = new File($this->base . $filename);
     $contentType = '';
     $this->c->debug(get_class($this), '::get ', $this->base . filename);
     $eProps = $this->propStorage->getProperties($f->uri);
     if (!empty($eProps['getcontenttype'])) {
         $contentType = $eProps['getcontenttype'][0];
     }
     if (empty($contentType)) {
         $contentType = MimeType::getByFilename($f->uri, 'text/plain');
     }
     $o = new WebdavObject($f->uri, NULL, $f->size(), $contentType, new Date($f->createdAt()), new Date($f->lastModified()));
     try {
         $f->open(FILE_MODE_READ);
         $o->setData($f->read($f->size()));
         $f->close();
     } catch (FileFoundException $e) {
         throw new ElementNotFoundException($filename . ' not found');
     }
     $this->c->debug('OBJ', $o->properties);
     return $o;
 }
コード例 #4
0
 /**
  * Load an image
  *
  * @param   peer.URL source
  * @return  string[2] data and contenttype
  */
 public function load($source)
 {
     return array(FileUtil::getContents(new File($source->getURL())), MimeType::getByFilename($source->getURL()));
 }