Example #1
0
File: ft.file.php Project: nob/joi
 public function process()
 {
     if ($this->field_data['tmp_name'] !== '') {
         $destination = BASE_PATH . '/' . $this->settings['destination'];
         $filename = File::cleanFilename($this->field_data['name']);
         if (File::upload($this->field_data['tmp_name'], $destination, $filename)) {
             return Path::tidy('/' . $this->settings['destination'] . '/' . $filename);
         } else {
             Log::fatal($this->field_data['tmp_name'] . ' could up not be uploaded to ' . $destination, 'core');
             return '';
         }
     }
 }
 public function fileclerk__filecheck()
 {
     $destination = Request::get('destination');
     $filename = Request::get('filename');
     $filename = File::cleanFilename($filename);
     $extension = File::getExtension($filename);
     // Merge configs
     $this->config = $this->tasks->merge_configs($destination);
     // S3 client
     self::load_s3();
     /**
      * @todo Need to update JS to accept this response for activating.
      */
     // First check if extension is allowed
     if (!self::extension_is_allowed($extension)) {
         $data = array('extension' => $extension);
         $file_not_allowed_template = File::get(__DIR__ . '/views/error-not-allowed.html');
         header('Content-Type', 'application/json');
         echo self::build_response_json(false, true, FILECLERK_DISALLOWED_FILETYPE, 'Filetype not allowed.', 'dialog', array('extension' => $extension), null, Parse::template($file_not_allowed_template, $data));
         exit;
     }
     // Get the S3 path
     $s3_path = self::build_s3_path();
     // Check if file already exists
     if (self::file_exists($s3_path, $filename)) {
         $overwrite = Request::get('overwrite');
         $file_exists_template = File::get(__DIR__ . '/views/file-exists.html');
         if (is_null($overwrite)) {
             header('Content-Type', 'application/json');
             echo self::build_response_json(false, true, FILECLERK_ERROR_FILE_EXISTS, FILECLERK_ERROR_FILE_EXISTS_MSG, 'dialog', null, null, Parse::template($file_exists_template, array('filename' => $filename)));
             exit;
         } elseif ($overwrite === 'false' || !$overwrite || $overwrite === 0) {
             $filename = self::increment_filename_unix($filename);
         }
     } else {
         header('Content-Type', 'application/json');
         echo self::build_response_json(true, false, FILECLERK_FILE_DOES_NOT_EXIST, 'File is clean!', null, null, null, null);
         exit;
     }
 }