Vegas CMF Media Upload Controller

Controller that controls the upload of the file.

Controller

uploadAction()

Make sure if you have uploader inside the di.


public function uploadAction()
{
    $this->view->disable();

    $files = array();

    if($this->request->isAjax() && $this->request->hasFiles()) {
        try {
            $uploader = $this->di->get('uploader'); //make sure if you have uploader inside the di
            $files[] = $uploader->setFiles($this->request->getUploadedFiles())->handle();
        } catch (\Exception $e) {
            $files[] = array('error' => $e->getMessage());
        }
    }

    return $this->response->setJsonContent(array('files' => $files));
}

You do not have to implement uploadAction manually. If your controller extends from CRUD then you can just extend from Controller\CrudUpload. To use CrudUpload you must install "vegas-cmf-media". CrudUpload automatically triggers uploadAction when you try to upload the file.


namespace Category\Controllers\Backend;

use Vegas\Mvc\Controller;

class CategoryController extends Controller\CrudUpload
{
    ...
}