Comur\ImageBundle\Controller\UploadController::uploadImageAction PHP Метод

uploadImageAction() публичный Метод

Save uploaded image according to comur_image field configuration
public uploadImageAction ( Request $request )
$request Symfony\Component\HttpFoundation\Request
    public function uploadImageAction(Request $request)
    {
        $config = json_decode($request->request->get('config'), true);
        $thumbsDir = $this->container->getParameter('comur_image.thumbs_dir');
        $thumbSize = $this->container->getParameter('comur_image.media_lib_thumb_size');
        $uploadUrl = $config['uploadConfig']['uploadUrl'];
        $uploadUrl = substr($uploadUrl, -strlen('/')) === '/' ? $uploadUrl : $uploadUrl . '/';
        // We must use a streamed response because the UploadHandler echoes directly
        $response = new StreamedResponse();
        $webDir = $config['uploadConfig']['webDir'];
        $webDir = substr($webDir, -strlen('/')) === '/' ? $webDir : $webDir . '/';
        if ($config['uploadConfig']['generateFilename']) {
            $filename = sha1(uniqid(mt_rand(), true));
        } else {
            $filename = $request->files->get('image_upload_file')->getClientOriginalName();
            if (file_exists($uploadUrl . $thumbsDir . '/' . $filename)) {
                $filename = time() . '-' . $filename;
            }
        }
        $galleryDir = $this->container->getParameter('comur_image.gallery_dir');
        $gThumbSize = $this->container->getParameter('comur_image.gallery_thumb_size');
        $ext = $request->files->get('image_upload_file')->getClientOriginalExtension();
        //('image_upload_file');
        $completeName = $filename . '.' . $ext;
        $controller = $this;
        $handlerConfig = array('upload_dir' => $uploadUrl, 'param_name' => 'image_upload_file', 'file_name' => $filename, 'generated_file_name' => $config['uploadConfig']['generateFilename'], 'upload_url' => $config['uploadConfig']['webDir'], 'min_width' => $config['cropConfig']['minWidth'], 'min_height' => $config['cropConfig']['minHeight'], 'image_versions' => array('thumbnail' => array('upload_dir' => $uploadUrl . $thumbsDir . '/', 'upload_url' => $config['uploadConfig']['webDir'] . '/' . $thumbsDir . '/', 'crop' => true, 'max_width' => $thumbSize, 'max_height' => $thumbSize)));
        $transDomain = $this->container->getParameter('comur_image.translation_domain');
        $errorMessages = array(1 => $this->get('translator')->trans('The uploaded file exceeds the upload_max_filesize directive in php.ini', array(), $transDomain), 2 => $this->get('translator')->trans('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', array(), $transDomain), 3 => $this->get('translator')->trans('The uploaded file was only partially uploaded', array(), $transDomain), 4 => $this->get('translator')->trans('No file was uploaded', array(), $transDomain), 6 => $this->get('translator')->trans('Missing a temporary folder', array(), $transDomain), 7 => $this->get('translator')->trans('Failed to write file to disk', array(), $transDomain), 8 => $this->get('translator')->trans('A PHP extension stopped the file upload', array(), $transDomain), 'post_max_size' => $this->get('translator')->trans('The uploaded file exceeds the post_max_size directive in php.ini', array(), $transDomain), 'max_file_size' => $this->get('translator')->trans('File is too big', array(), $transDomain), 'min_file_size' => $this->get('translator')->trans('File is too small', array(), $transDomain), 'accept_file_types' => $this->get('translator')->trans('Filetype not allowed', array(), $transDomain), 'max_number_of_files' => $this->get('translator')->trans('Maximum number of files exceeded', array(), $transDomain), 'max_width' => $this->get('translator')->trans('Image exceeds maximum width', array(), $transDomain), 'min_width' => $this->get('translator')->trans('Image requires a minimum width (%min%)', array('%min%' => $config['cropConfig']['minWidth']), $transDomain), 'max_height' => $this->get('translator')->trans('Image exceeds maximum height', array(), $transDomain), 'min_height' => $this->get('translator')->trans('Image requires a minimum height (%min%)', array('%min%' => $config['cropConfig']['minHeight']), $transDomain), 'abort' => $this->get('translator')->trans('File upload aborted', array(), $transDomain), 'image_resize' => $this->get('translator')->trans('Failed to resize image', array(), $transDomain));
        $response->setCallback(function () use($handlerConfig, $errorMessages) {
            new UploadHandler($handlerConfig, true, $errorMessages);
        });
        return $response->send();
    }