Example #1
0
 /**
  * Creates a new file in the directory
  *
  * @param string $name Name of the file
  * @param resource|string $data Initial payload
  * @return null|string
  */
 public function createFile($name, $data = null)
 {
     list($app) = explode('/', $this->_path);
     if (is_resource($data)) {
         $content = new Horde_Stream_Existing(array('stream' => $data));
         $type = Horde_Mime_Magic::analyzeData($content->getString(0, 100), $this->_mimedb);
     } else {
         $content = $data;
         $type = Horde_Mime_Magic::analyzeData($content, $this->_mimedb);
     }
     if (!$type) {
         $type = Horde_Mime_Magic::filenameToMime($name);
     }
     try {
         $this->_registry->callByPackage($app, 'put', array($this->_path . '/' . $name, $content, $type));
     } catch (Horde_Exception $e) {
         throw new DAV\Exception($e->getMessage(), $e->getCode(), $e);
     }
 }