public function indexAction() { $request = $this->getRequest(); if (!$request->isPost()) { $this->getHelper('Redirector')->goto('index', 'index'); // action, controller } $c = Zend_Registry::get('config'); $apiKey = Zend_Filter::get($request->getPost('apikey'), 'Alnum'); try { $user = User::findByApiKey($apiKey); if ($user === null) { $this->view->assign('response', 'Invalid API key.'); } else { $user->setIp($request->getServer('REMOTE_ADDR')); } } catch (Zend_Db_Adapter_Exception $e) { $this->view->assign('response', $e->getMessage()); } if (isset($user)) { if ($_FILES['file']['error'] === 0) { $file = new File(); $file->setFileName($_FILES['file']['name']); $file->setFileSize($_FILES['file']['size']); $file->setTmpName($_FILES['file']['tmp_name']); $file->setUploadedBy($user); try { $url = $file->save(); $this->view->assign('response', $url . "\n"); } catch (Exception $e) { $this->view->assign('response', $e->getMessage()); } } else { switch ($_FILES['file']['error']) { case UPLOAD_ERR_OK: break; case UPLOAD_ERR_INI_SIZE: throw new Exception('The uploaded file exceeds the upload_max_filesize directive (' . ini_get('upload_max_filesize') . ') in php.ini.'); break; case UPLOAD_ERR_FORM_SIZE: throw new Exception('The uploaded file exceeds the MAX_FILE_SIZE directive' . 'that was specified in the HTML form.'); break; case UPLOAD_ERR_PARTIAL: throw new Exception('The uploaded file was only partially uploaded.'); break; case UPLOAD_ERR_NO_FILE: throw new Exception('No file was uploaded.'); break; case UPLOAD_ERR_NO_TMP_DIR: throw new Exception('Missing a temporary folder.'); break; case UPLOAD_ERR_CANT_WRITE: throw new Exception('Failed to write file to disk.'); break; default: throw new Exception('Unknown File Error.'); } } } }
public static function findByAccessCode($accessCode) { $file = new File(); $db = Zend_Registry::get('db'); $fileRow = $db->fetchRow('SELECT id, file_name FROM files WHERE access_code = ? AND active = 1', $accessCode); if (!$fileRow) { return null; } if (!file_exists("files/" . $fileRow->file_name)) { throw new Exception('Sorry, this file has been deleted from the file system.'); } $file->setFileName($fileRow->file_name); return $file; }
/** * Get Storage Revisions * * @param fromRevision - optional - * Revision Number * * @return A workspaceChanges object is returned with a list of all the file and folder revisions. */ public function getStorageRevisions($fromRevision) { $urld = 'dpi/v1/storage/revisions'; if (strlen($fromRevision) == 0) { $parameters = array(); } else { $parameters = array('fromRevision' => $fromRevision); } $this->response = $this->restTransportInstance->sendRequest($urld, $parameters, self::HTTP_GET, $this->authToken); $responseBody = simplexml_load_string($this->response); $returnObject = new StorageChanges(); if ($responseBody === false) { $errorCode = 'N/A'; $errorMessage = 'The server has encountered an error, please try again.'; $errorObject = new ErrorStatus($errorCode, $errorMessage); $returnObject->setErrorStatus($errorObject); } else { $errorStatus = $responseBody->errorStatus; if (empty($errorStatus)) { $returnObject->setCurrentUsage((string) $responseBody->currentUsage); $returnObject->setRevision((string) $responseBody->revision); $returnObject->setRevisionCount((string) $responseBody->revisionCount); $returnObject->setStatusDisplay((string) $responseBody->statusDisplay); $returnObject->setStorageQuota((string) $responseBody->storageQuota); $returnObject->setWorkspaceId((string) $responseBody->workspaceId); $files = array(); $filesTag = (string) $responseBody->file->count(); if (!empty($filesTag)) { foreach ($responseBody->file as $currentFile) { if ($currentFile->count() > 0) { $file = new File(); $file->setCreatedOn((string) $currentFile->createdOn); $file->setDeleteStatus((string) $currentFile->deleteStatus); $file->setFileId((string) $currentFile->fileId); $file->setFileName((string) $currentFile->fileName); $file->setFolderId((string) $currentFile->folderId); $file->setLastUpdatedOn((string) $currentFile->lastUpdatedOn); $file->setRevision((string) $currentFile->revision); array_push($files, $file); } } $returnObject->setFiles($files); } $folders = array(); $foldersTag = (string) $responseBody->folder->count(); if (!empty($foldersTag)) { foreach ($responseBody->folder as $currentFolder) { if ($currentFolder->count() > 0) { $folder = new Folder(); $folder->setCreatedOn((string) $currentFolder->createdOn); $folder->setDeletedStatus((string) $currentFolder->deletedStatus); $folder->setFolderId((string) $currentFolder->folderId); $folder->setFolderType((string) $currentFolder->folderType); $folder->setLastUpdatedOn((string) $currentFolder->lastUpdatedOn); $folder->setRevision((string) $currentFolder->revision); $folder->setShareInvitationPending((string) $currentFolder->shareInvitationPending); $folder->setSize((string) $currentFolder->size); $permissions = array(); $permissionsTag = (string) $currentFolder->permissions->count(); if (!empty($permissionsTag)) { foreach ($currentFolder->permissions as $currentPermission) { $permission = new Permission(); $permission->setWsPermissionName((string) $currentPermission->wsPermissionName); array_push($permissions, $permission); } } $folder->setPermissions($permissions); array_push($folders, $folder); } } $returnObject->setFolders($folders); } } else { $errorCode = (string) $responseBody->errorStatus->code; $errorMessage = (string) $responseBody->errorStatus->message; $errorObject = new ErrorStatus($errorCode, $errorMessage); $returnObject->setErrorStatus($errorObject); } } return $returnObject; }