public function uploadAction() { if (!$this->getDi()->uploadAcl->checkPermission($this->getParam('prefix'), Am_Upload_Acl::ACCESS_WRITE, $this->getDi()->auth->getUser())) { throw new Am_Exception_AccessDenied(); } $secure = $this->getParam('secure', false); $upload = new Am_Upload($this->getDi()); $upload->setPrefix($this->getParam('prefix')); $upload->loadFromStored(); $ids_before = $this->getUploadIds($upload); $upload->processSubmit('upload', false); //find currently uploaded file $x = array_diff($this->getUploadIds($upload), $ids_before); $upload_id = array_pop($x); try { $upload = $this->getDi()->uploadTable->load($upload_id); $data = array('ok' => true, 'name' => $upload->getName(), 'size_readable' => $upload->getSizeReadable(), 'upload_id' => $secure ? Am_Form_Element_Upload::signValue($upload->pk()) : $upload->pk(), 'mime' => $upload->mime); echo $this->getJson($data); } catch (Am_Exception $e) { echo $this->getJson(array('ok' => false, 'error' => ___('No files uploaded'))); } }
public function run() { $form = $this->grid->getForm(); $form->setAttribute('target', '_top'); $upload = new Am_Upload(Am_Di::getInstance()); $upload->setPrefix($this->grid->getCompleteRequest()->getParam('prefix')); $upload->loadFromStored(); $ids_before = $this->getUploadIds($upload); if ($form->isSubmitted() && $upload->processSubmit('upload')) { //find currently uploaded file $upload_id = array_pop(array_diff($this->getUploadIds($upload), $ids_before)); $upload = Am_Di::getInstance()->uploadTable->load($upload_id); $upload->desc = $this->grid->getCompleteRequest()->getParam('desc'); $upload->save(); return $this->grid->redirectBack(); } echo $this->renderTitle(); echo $form; }
protected function updateValue() { $name = $this->getName(); //proceess upload only once fo each name static $executed = array(); if (!isset($executed[$name])) { $executed[$name] = 1; $name = $this->getName(); $upload = new Am_Upload(Am_Di::getInstance()); $upload->setPrefix($this->prefix); $upload->loadFromStored(); $ids_before = $this->getUploadIds($upload); $upload->processSubmit($name); //find currently uploaded file $x = array_diff($this->getUploadIds($upload), $ids_before); $upload_id = array_pop($x); if ($upload_id) { $this->upload_id = $upload_id; } } $value = null; foreach ($this->getDataSources() as $ds) { if (null !== ($value = $ds->getValue($name))) { break; } } if (empty($this->attributes['multiple'])) { $value = $this->upload_id ? $this->upload_id : $value; } else { if ($value) { $value = $this->upload_id ? array_merge($value, array($this->upload_id)) : $value; } else { $value = $this->upload_id ? array($this->upload_id) : null; } } $this->setValue($value); }