/**
  *
  *
  * @return unknown
  */
 public function write_file()
 {
     $path = $this->get_file_path();
     air2_mkdir(dirname($path));
     $params = $this->srs;
     $params['meta'] = $this->meta;
     // handle file uploads first, because we need to alter $params
     // to reflect target file name
     if ($this->has_files) {
         foreach ($params as $ques_uuid => $param_value) {
             if (is_array($param_value) && isset($param_value['orig_name'])) {
                 $upload_dir = sprintf("%s/%s.uploads", dirname($path), $this->uuid);
                 $target_file = sprintf("%s/%s.%s", $upload_dir, $ques_uuid, $param_value['file_ext']);
                 air2_mkdir($upload_dir);
                 if (move_uploaded_file($param_value['tmp_name'], $target_file)) {
                     chmod($target_file, 0664);
                 }
                 $params[$ques_uuid]['tmp_name'] = $target_file;
                 // for reaper
             }
         }
     }
     $json = Encoding::json_encode_utf8($params);
     $bytes = file_put_contents($path, $json);
     return $bytes;
 }
Пример #2
0
 /**
  * Copies a readable file, overwriting this Tank's file.
  *
  * @param string  $source
  * @return boolean success
  */
 public function copy_file($source)
 {
     air2_mkdir($this->get_folder_path());
     // make sure it exists
     $dest = $this->get_file_path();
     if (is_readable($source) && $dest) {
         $this->delete_file();
         copy($source, $dest);
         chmod($dest, 0770);
         return true;
     }
     return false;
 }
 /**
  * Returns the absolute file path to the cached RSS feed file.
  *
  * @return $rss_feed_path
  */
 public function get_rss_cache_path()
 {
     if (!is_dir(AIR2_RSS_CACHE_ROOT . '/project')) {
         air2_mkdir(AIR2_RSS_CACHE_ROOT . '/project');
     }
     return sprintf("%s/project/%s.rss", AIR2_RSS_CACHE_ROOT, $this->prj_name);
 }
 /**
  * Custom setter for the image.
  *
  * @param array|string $image
  */
 public function set_image($image)
 {
     if (is_array($image)) {
         $name = $image['name'];
         $path = $image['tmp_name'];
     } elseif (is_string($image) && is_readable($image)) {
         $name = basename($image);
         $path = $image;
     } else {
         throw new Exception("Invalid image");
     }
     // validate image
     if (!is_readable($path)) {
         throw new Exception("Invalid image path: {$path}");
     }
     $img_info = getimagesize($path);
     if (!$img_info) {
         throw new Exception("Invalid image file: {$name}");
     }
     // check/create image directory
     if (!$this->img_uuid) {
         $this->img_uuid = air2_generate_uuid();
     }
     $dir = self::get_directory($this->img_ref_type, $this->img_uuid);
     air2_mkdir($dir);
     if (!is_writable($dir)) {
         throw new Exception("Cannot write to: {$dir}");
     }
     // looks okay... raw-set the info
     $this->_set('img_file_name', air2_fileify($name));
     $this->_set('img_file_size', filesize($path));
     $this->_set('img_content_type', $img_info['mime']);
     $this->_set('img_dtim', air2_date());
     $this->_set_image = $path;
 }
 /**
  * Constructor
  *
  * Make sure temp-file directory is writable.
  *
  * @param string  $directory
  * @param array   $config
  */
 function __construct($directory, $config)
 {
     // check directory existence
     air2_rmdir($directory);
     // clean any old files
     if (!air2_mkdir($directory)) {
         throw new Exception("Unable to create directory {$directory}");
     }
     // make sure directory is writable
     if (!is_writable($directory)) {
         throw new Exception("Unable to write to directory {$directory}");
     }
     $this->output_dir = $directory;
     $this->config = $config;
     // create a yaml dumper
     $this->dumper = new sfYamlDumper();
 }