Example #1
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;
 }