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 info($secure = false) { return array('name' => $this->getName(), 'size_readable' => Am_Storage_File::getSizeReadable($this->getSize()), 'upload_id' => $secure ? Am_Form_Element_Upload::signValue($this->storage->getPath($this->getPath())) : $this->storage->getPath($this->getPath()), 'mime' => $this->getMime(), 'ok' => true); }