AdminBundle/Service/UploadHandler.php
public function post($printResponse = true)
    {
        if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
            return $this->delete($printResponse);
        }
        $upload = isset($_FILES[$this->options['param_name']]) ?
            $_FILES[$this->options['param_name']] : null;
        // Parse the Content-Disposition header, if available:
        /*$fileName = $this->get_server_var('HTTP_CONTENT_DISPOSITION') ?
            rawurldecode(preg_replace(
                '/(^[^"]+")|("$)/',
                '',
                $this->get_server_var('HTTP_CONTENT_DISPOSITION')
            )) : null;*/
        $fileName = $this->options['entity_slug'].'-'.md5(uniqid());
        // Parse the Content-Range header, which has the following form:
        // Content-Range: bytes 0-524287/2000000
        $contentRange = $this->get_server_var('HTTP_CONTENT_RANGE') ?
            preg_split('/[^0-9]+/', $this->get_server_var('HTTP_CONTENT_RANGE')) : null;
        $size =  $contentRange ? $contentRange[3] : null;
        $files = array();
        if ($upload && is_array($upload['tmp_name'])) {

            /** @var Product $entity */
            $entity = $this->entityManager->getRepository($this->options['entity_path'])->find($this->options['entity_id']);

            if (!$entity) {
                throw new NotFoundHttpException('Unable to find entity.');
            }


            // param_name is an array identifier like "files[]",
            // $_FILES is a multi-dimensional array:
            foreach ($upload['tmp_name'] as $index => $value) {
                $files[] = $this->handle_file_upload(
                    $upload['tmp_name'][$index],
                    $fileName ? $fileName : $upload['name'][$index],
                    $size ? $size : $upload['size'][$index],
                    $upload['type'][$index],
                    $upload['error'][$index],
                    $index,
                    $contentRange
                );

                // save the file name in the database
                /** @var Image $image */
                if($this->options['entity_path'] == 'BlogBundle:Post') {
                    $image = new PostImage();
                }elseif($this->options['entity_path'] == 'CatalogueBundle:Product'){
                    $image = new ProductImage();
                }
                $image->setPath('/uploads/images/'.$this->options['type'].'/'.$entity->getId().'/'.$files[$index]->name);
                $this->entityManager->persist($image);

                $entity->addImage($image);

                //add crop center thumbmail image
                // '260'=>array('w'=>260,'h'=>123),
                // '160'=>array('w'=>160,'h'=>100),      
                // '104'=>array('w'=>104,'h'=>56),
                // '142'=>array('w'=>142,'h'=>88)
                //create source image
                if(isset($upload['type'][0]) && isset($upload['name'][0])){
                    $extension = $upload['type'][0];
                    $arr=array();
                    if($extension=='image/jpeg') {
                        $source = imagecreatefromjpeg($this->options['upload_dir'].$files[$index]->name);
                        if(preg_match('/\.jpeg/', $files[$index]->name)) $arr = explode('.jpeg', $files[$index]->name);
                        if(preg_match('/\.jpg/', $files[$index]->name)) $arr = explode('.jpg', $files[$index]->name);
                        $img_name = $arr[0];
                    }else if($extension=='image/gif') {
                        $source = imagecreatefromgif($this->options['upload_dir'].$files[$index]->name);
                        if(preg_match('/\.gif/', $files[$index]->name)) $arr = explode('.gif', $files[$index]->name);
                        $img_name = $arr[0];
                    }else if($extension=='image/png') {
                        $source = imagecreatefrompng($this->options['upload_dir'].$files[$index]->name);
                        if(preg_match('/\.png/', $files[$index]->name)) $arr = explode('.png', $files[$index]->name);
                        $img_name = $arr[0];
                    }
                    $this->resizeImage($source, $img_name.'_400', 400, 250);
                    $this->resizeImage($source, $img_name.'_380', 380, 180);
                    $this->resizeImage($source, $img_name.'_260', 260, 123);
                    $this->resizeImage($source, $img_name.'_142', 142, 88);
                    
                }
            }

            $this->entityManager->persist($entity);
            $this->entityManager->flush();
        } else {
            // param_name is a single object identifier like "file",
            // $_FILES is a one-dimensional array:
            $files[] = $this->handle_file_upload(
                isset($upload['tmp_name']) ? $upload['tmp_name'] : null,
                $fileName ? $fileName : (isset($upload['name']) ?
                    $upload['name'] : null),
                $size ? $size : (isset($upload['size']) ?
                    $upload['size'] : $this->get_server_var('CONTENT_LENGTH')),
                isset($upload['type']) ?
                $upload['type'] : $this->get_server_var('CONTENT_TYPE'),
                isset($upload['error']) ? $upload['error'] : null,
                null,
                $contentRange
            );
        }

        return $this->generate_response(
            array($this->options['param_name'] => $files),
            $printResponse
        );
    }
public function post($printResponse = true)
    {
        if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
            return $this->delete($printResponse);
        }
        $upload = isset($_FILES[$this->options['param_name']]) ?
            $_FILES[$this->options['param_name']] : null;
        // Parse the Content-Disposition header, if available:
        /*$fileName = $this->get_server_var('HTTP_CONTENT_DISPOSITION') ?
            rawurldecode(preg_replace(
                '/(^[^"]+")|("$)/',
                '',
                $this->get_server_var('HTTP_CONTENT_DISPOSITION')
            )) : null;*/
        $fileName = $this->options['entity_slug'].'-'.md5(uniqid());
        // Parse the Content-Range header, which has the following form:
        // Content-Range: bytes 0-524287/2000000
        $contentRange = $this->get_server_var('HTTP_CONTENT_RANGE') ?
            preg_split('/[^0-9]+/', $this->get_server_var('HTTP_CONTENT_RANGE')) : null;
        $size =  $contentRange ? $contentRange[3] : null;
        $files = array();
        if ($upload && is_array($upload['tmp_name'])) {

            /** @var Product $entity */
            $entity = $this->entityManager->getRepository($this->options['entity_path'])->find($this->options['entity_id']);

            if (!$entity) {
                throw new NotFoundHttpException('Unable to find entity.');
            }


            // param_name is an array identifier like "files[]",
            // $_FILES is a multi-dimensional array:
            foreach ($upload['tmp_name'] as $index => $value) {
                $files[] = $this->handle_file_upload(
                    $upload['tmp_name'][$index],
                    $fileName ? $fileName : $upload['name'][$index],
                    $size ? $size : $upload['size'][$index],
                    $upload['type'][$index],
                    $upload['error'][$index],
                    $index,
                    $contentRange
                );

                // save the file name in the database
                /** @var Image $image */
                if($this->options['entity_path'] == 'BlogBundle:Post') {
                    $image = new PostImage();
                }elseif($this->options['entity_path'] == 'CatalogueBundle:Product'){
                    $image = new ProductImage();
                }
                $image->setPath('/uploads/images/'.$this->options['type'].'/'.$entity->getId().'/'.$files[$index]->name);
                $this->entityManager->persist($image);

                $entity->addImage($image);

                //add crop center thumbmail image
                // '260'=>array('w'=>260,'h'=>123),
                // '160'=>array('w'=>160,'h'=>100),      
                // '104'=>array('w'=>104,'h'=>56),
                // '142'=>array('w'=>142,'h'=>88)
                //create source image
                if(isset($upload['type'][0]) && isset($upload['name'][0])){
                    $extension = $upload['type'][0];
                    $arr=array();
                    if($extension=='image/jpeg') {
                        $source = imagecreatefromjpeg($this->options['upload_dir'].$files[$index]->name);
                        if(preg_match('/\.jpeg/', $files[$index]->name)) $arr = explode('.jpeg', $files[$index]->name);
                        if(preg_match('/\.jpg/', $files[$index]->name)) $arr = explode('.jpg', $files[$index]->name);
                        $img_name = $arr[0];
                    }else if($extension=='image/gif') {
                        $source = imagecreatefromgif($this->options['upload_dir'].$files[$index]->name);
                        if(preg_match('/\.gif/', $files[$index]->name)) $arr = explode('.gif', $files[$index]->name);
                        $img_name = $arr[0];
                    }else if($extension=='image/png') {
                        $source = imagecreatefrompng($this->options['upload_dir'].$files[$index]->name);
                        if(preg_match('/\.png/', $files[$index]->name)) $arr = explode('.png', $files[$index]->name);
                        $img_name = $arr[0];
                    }
                    $this->resizeImage($source, $img_name.'_400', 400, 250);
                    $this->resizeImage($source, $img_name.'_380', 380, 180);
                    $this->resizeImage($source, $img_name.'_260', 260, 123);
                    $this->resizeImage($source, $img_name.'_142', 142, 88);
                    
                }
            }

            $this->entityManager->persist($entity);
            $this->entityManager->flush();
        } else {
            // param_name is a single object identifier like "file",
            // $_FILES is a one-dimensional array:
            $files[] = $this->handle_file_upload(
                isset($upload['tmp_name']) ? $upload['tmp_name'] : null,
                $fileName ? $fileName : (isset($upload['name']) ?
                    $upload['name'] : null),
                $size ? $size : (isset($upload['size']) ?
                    $upload['size'] : $this->get_server_var('CONTENT_LENGTH')),
                isset($upload['type']) ?
                $upload['type'] : $this->get_server_var('CONTENT_TYPE'),
                isset($upload['error']) ? $upload['error'] : null,
                null,
                $contentRange
            );
        }

        return $this->generate_response(
            array($this->options['param_name'] => $files),
            $printResponse
        );
    }
Post method

@param bool $printResponse

@throws NotFoundHttpException
@return mixed