function loadPOST() { parent::loadPOST(); if ($_GET[$this->name . '_upload_action']) { // This is JavaScript upload. We do not want to trigger form submission event $_POST = array(); } if ($_GET[$this->name . '_upload_action'] || $this->isUploaded()) { if ($c = $this->getController()) { try { $c->set('filestore_volume_id', 1); $c->set('original_filename', $this->getOriginalName()); $c->set('filestore_type_id', $c->getFiletypeID($this->getOriginalType())); $c->import($this->getFilePath()); $c->update(); } catch (Exception $e) { $this->api->logger->logException($e); $this->uploadFailed($e->getMessage()); } $this->uploadComplete($c->get()); } } if ($_POST[$this->name . '_token']) { $a = explode(',', $_POST[$this->name . '_token']); $b = array(); foreach ($a as $val) { if ($val) { $b[] = $val; } } $this->set(join(',', filter_var_array($b, FILTER_VALIDATE_INT))); } else { $this->set($this->default_value); } }
function loadPOST() { parent::loadPOST(); if (isset($_FILES[$this->name . '_f'])) { $f = $_FILES[$this->name . '_f']; // Uploading something! if ($f['error']) { $this->uploadFailed('Error: ' . $f['error']); } if ($this->model) { $model = $this->model; $model->set('filestore_volume_id', $model->getAvailableVolumeID()); $model->set('original_filename', $this->getFilePath()); $model->set('filestore_type_id', $model->getFiletypeID($this->getOriginalType())); $model->import($this->getFilePath()); $model->save(); $this->hook('uploaded', array($model)); $this->uploadComplete($this->model->id, $this->model->get()); } } $this->uploadFailed('You should set model for this field'); }
public function loadPOST() { parent::loadPOST(); if ($_GET[$this->name . '_upload_action']) { // This is JavaScript upload. We do not want to trigger form submission event $_POST = array(); } if ($_GET[$this->name . '_upload_action'] || $this->isUploaded()) { if ($this->model) { try { if (!file_exists($this->getFilePath())) { throw $this->exception('File upload was blocked by the webserver (post: ' . json_encode($_POST) . ', get: ' . json_encode($_GET) . ')', 'ForUser'); } $model = $this->model; $model->set($this->getVolumeIDFieldName(), $model->getAvailableVolumeID()); $model->set($this->getOriginalFilenameFieldName(), $this->getOriginalName()); $model->set($this->getTypeIDFieldName(), $model->getFiletypeID($this->getOriginalType(), $model->policy_add_new_type)); $model->import($this->getFilePath()); $model->save(); } catch (Exception $e) { $this->app->logger->logCaughtException($e); if ($e instanceof Exception_ForUser) { // nicer error for user $this->uploadFailed($e->getMessage()); //.', error: '.$this->getFileError()); //more user friendly } if ($e instanceof BaseException) { $e->addMoreInfo('upload_error', $this->getFileError()); } echo '<script>$=window.top.$;'; $_POST['ajax_submit'] = 1; $this->app->addHook('post-js-execute', function () { echo ';</script>'; }); $this->app->caughtException($e); } $this->uploadComplete($model->get()); } else { // else do nothing null; } } if ($_POST[$this->name . '_token']) { $a = explode(',', $_POST[$this->name . '_token']); $b = array(); foreach ($a as $val) { if ($val) { $b[] = $val; } } $this->set(implode(',', filter_var_array($b, FILTER_VALIDATE_INT))); } else { $this->set($this->default_value); } }