コード例 #1
0
ファイル: file.php プロジェクト: piotrtheis/jelly
 /**
  * Logic to deal with uploading the image file and generating thumbnails according to
  * what has been specified in the $thumbnails array.
  *
  * @param   Validation   $validation
  * @param   Jelly_Model  $model
  * @param   Jelly_Field  $field
  * @return  bool
  */
 public function _upload(Validation $validation, $model, $field)
 {
     // Get the file from the validation object
     $file = $validation[$field];
     //no need upload if post helper isset
     if (!empty($_POST[self::$post_file_helper_prefix . $this->name])) {
         $this->_filename = $_POST[self::$post_file_helper_prefix . $this->name];
         return TRUE;
     }
     // Sanitize the filename
     $file['name'] = preg_replace('/[^a-z0-9-\\.]/', '-', strtolower($file['name']));
     // Strip multiple dashes
     $file['name'] = preg_replace('/-{2,}/', '-', $file['name']);
     // Upload a file?
     if (($filename = Upload::save($file, NULL, $this->path)) !== FALSE) {
         // Standardise slashes
         $filename = str_replace('\\', '/', $filename);
         // Chop off the original path
         // $value = str_replace($this->path, '', $filename);
         $value = str_replace(ltrim($_SERVER['DOCUMENT_ROOT'], '/'), '', $filename);
         // Ensure we have no leading slash
         if (is_string($value)) {
             $value = trim($value, '/');
         }
         // Garbage collect
         $this->_delete_old_file($model->original($this->name), $this->path);
         // Set the saved filename
         $this->_filename = '/' . $value;
         $_POST[self::$post_file_helper_prefix . $this->name] = $this->_filename;
     }
     return TRUE;
 }