AdminBundle/Service/UploadHandler.php
public function delete($printResponse = true)
    {
        $fileName = $this->get_file_name_param();
        $filePath = $this->get_upload_path($fileName);
       
        
        /** @var Image $entity */
        $qb = $this->entityManager->getRepository($this->options['entity_image_path'])
                    ->createQueryBuilder('i');
        $image = $qb->where($qb->expr()->like('i.path', ':path'))
            ->setParameter('path','%'.$fileName.'%')
            ->getQuery()
            ->getOneOrNullResult();
            
        /** @var Product $entity */
        $entity = $this->entityManager->getRepository($this->options['entity_path'])->find($this->options['entity_id']);

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

        //this line reutn true when all is false ...&& 
        $success = is_file($filePath) && $fileName[0] !== '.' && unlink($filePath);
        
        if ($success) {
            foreach ($this->options['image_versions'] as $version => $options) {
               
                if (!empty($version)) {
                    $file = $this->get_upload_path($fileName, $version);
                    if (is_file($file)) {
                        unlink($file);
                    }
                }
                // remove the file name from the database
                $entity->removeImage($image);
                $this->entityManager->remove($image);
            }

            $this->entityManager->persist($entity);
            $this->entityManager->flush();
        }

        return $this->generate_response(array('success' => $success), $printResponse);
    }
public function delete($printResponse = true)
    {
        $fileName = $this->get_file_name_param();
        $filePath = $this->get_upload_path($fileName);
       
        
        /** @var Image $entity */
        $qb = $this->entityManager->getRepository($this->options['entity_image_path'])
                    ->createQueryBuilder('i');
        $image = $qb->where($qb->expr()->like('i.path', ':path'))
            ->setParameter('path','%'.$fileName.'%')
            ->getQuery()
            ->getOneOrNullResult();
            
        /** @var Product $entity */
        $entity = $this->entityManager->getRepository($this->options['entity_path'])->find($this->options['entity_id']);

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

        //this line reutn true when all is false ...&& 
        $success = is_file($filePath) && $fileName[0] !== '.' && unlink($filePath);
        
        if ($success) {
            foreach ($this->options['image_versions'] as $version => $options) {
               
                if (!empty($version)) {
                    $file = $this->get_upload_path($fileName, $version);
                    if (is_file($file)) {
                        unlink($file);
                    }
                }
                // remove the file name from the database
                $entity->removeImage($image);
                $this->entityManager->remove($image);
            }

            $this->entityManager->persist($entity);
            $this->entityManager->flush();
        }

        return $this->generate_response(array('success' => $success), $printResponse);
    }
Delete method

@param bool $printResponse

@throws NotFoundHttpException
@return mixed