Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $adapter = new ZendFileTransferAdapterHttp();
- $adapter->addFilter('filerenameupload', array(
- 'target' => BASE_DIR . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR .
- 'img' . DIRECTORY_SEPARATOR . 'gallery' .
- DIRECTORY_SEPARATOR . 'image.jpg',
- 'randomize' => true,
- ));
- var_dump($adapter->isValid()); // true
- if (!$adapter->receive()) {
- $messages = $adapter->getMessages();
- echo implode("n", $messages);
- }
- protected function moveUploadedFile($sourceFile, $targetFile)
- {
- ErrorHandler::start();
- $result = move_uploaded_file($sourceFile, $targetFile);
- $warningException = ErrorHandler::stop();
- if (!$result || null !== $warningException) {
- throw new ExceptionRuntimeException(
- sprintf("File '%s' could not be renamed. An error occurred while processing the file.", $sourceFile), 0, $warningException
- );
- }
- return $result;
- }
- public function uploadAction()
- {
- $adapter = new ZendFileTransferAdapterHttp();
- $adapter->setDestination(BASE_DIR . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR .
- 'img' . DIRECTORY_SEPARATOR . 'gallery' . DIRECTORY_SEPARATOR);
- // Returns all known internal file information
- $adapter->addFilter('FileRename', array('target' => $adapter->getDestination() .
- DIRECTORY_SEPARATOR . rand(2, 10) . '.jpeg',
- 'overwrite' => true));
- if (!$adapter->receive()) {
- $messages = $adapter->getMessages();
- return new ViewModel(['messages' => $messages]);
- } else {
- $this->flashMessenger()->addSuccessMessage('Upload success');
- $this->redirect()->toRoute('admin', ['controller' => 'gallery',
- 'action' => 'index']);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement