Php 将Dropzone与Symfony2文件集成&引用;不存在

Php 将Dropzone与Symfony2文件集成&引用;不存在,php,exception,symfony,dropzone.js,Php,Exception,Symfony,Dropzone.js,我正在尝试将Dropzone与symfony集成。但是,当我选择多个文件时,会出现以下异常: The file "" does not exist 500 Internal Server Error - FileNotFoundException Stack Trace in /var/www/thegabrielhotel/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/File/MimeType/M

我正在尝试将Dropzone与symfony集成。但是,当我选择多个文件时,会出现以下异常:

 The file "" does not exist
 500 Internal Server Error - FileNotFoundException
 Stack Trace    
    in /var/www/thegabrielhotel/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php at line 115  -
            public function guess($path)
            {
                if (!is_file($path)) {
                    throw new FileNotFoundException($path);
                }
                if (!is_readable($path)) {
    at MimeTypeGuesser ->guess ('')
    in /var/www/thegabrielhotel/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/File/File.php at line 87  +
    at File ->getMimeType ()
    in /var/www/thegabrielhotel/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/File/File.php at line 64  +
    at File ->guessExtension ()
    in /var/www/thegabrielhotel/src/Gbr/BEBundle/Document/OverviewPhoto.php at line 71  +
    at OverviewPhoto ->preUpload ()
    in /var/www/thegabrielhotel/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php at line 525  +
    at ClassMetadataInfo ->invokeLifecycleCallbacks ('prePersist', object(OverviewPhoto))
    in /var/www/thegabrielhotel/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php at line 953  +
    at UnitOfWork ->persistNew (object(ClassMetadata), object(OverviewPhoto))
    in /var/www/thegabrielhotel/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php at line 1775  +
    at UnitOfWork ->doPersist (object(OverviewPhoto), array('000000001f48b19e00007fd7abcd7e2a' => object(OverviewPhoto)))
    in /var/www/thegabrielhotel/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php at line 1739  +
    at UnitOfWork ->persist (object(OverviewPhoto))
    in /var/www/thegabrielhotel/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/DocumentManager.php at line 384  +
    at DocumentManager ->persist (object(OverviewPhoto))
    in /var/www/thegabrielhotel/src/Gbr/BEBundle/Controller/DefaultController.php at line 57  +
    at DefaultController ->postOverviewPhotosAction (object(Request))
    at call_user_func_array (array(object(DefaultController), 'postOverviewPhotosAction'), array(object(Request)))
    in kernel.root_dir/bootstrap.php.cache at line 2843  +
    at HttpKernel ->handleRaw (object(Request), '1')
    in kernel.root_dir/bootstrap.php.cache at line 2817  +
    at HttpKernel ->handle (object(Request), '1', true)
    in kernel.root_dir/bootstrap.php.cache at line 2946  +
    at ContainerAwareHttpKernel ->handle (object(Request), '1', true)
    in kernel.root_dir/bootstrap.php.cache at line 2248  +
    at Kernel ->handle (object(Request))
    in /var/www/thegabrielhotel/web/app_dev.php at line 28  +
以下是dropzone的布局部分:

<form action="{{ path("gbr_be_post_overview_photos") }}" class="dropzone" id="my-dropzone">
                        </form>
概览照片
文档:

<?php
namespace Gbr\BEBundle\Document;

use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * @MongoDB\Document(collection="overview_photos", repositoryClass="Gbr\BEBundle\Repository\OverviewPhotoRepository")
 */
class OverviewPhoto
{
    /**
     * @MongoDB\Id(strategy="AUTO")
     */
    protected $id;

    /**
     * @MongoDB\Date
     */
    protected $updated_at;

    /**
     * @Assert\Image
     */
    protected $photo_file;

    /**
     * @MongoDB\String
     */
    protected $photo_name;


    public function getUploadDir()
    {
        return 'uploads/images/overview/slider';
    }

    public function getRootUploadDir()
    {
        return "/../../../../web/". $this->getUploadDir();
    }

    public function getWebPath()
    {
        return $this->photo_name === null ? null : "/".$this->getUploadDir()."/".$this->photo_name;
    }

    public function getAbsolutePath()
    {
        return $this->photo_name === null ? null : "/".$this->getRootUploadDir()."/".$this->photo_name;
    }

    /**
     * WARNING!! PreUpdate no fired since $file is not managed by Doctrine.
     * SOLUTION: use PostLoad() Event.
     * @MongoDB\PostLoad()
     */
    public function postLoad()
    {
        $this->setUpdatedAt(new \DateTime());
    }

    /**
     * @MongoDB\PrePersist()
     * @MongoDB\PreUpdate()
     */
    public function preUpload()
    {
        if($this->photo_file !== null)
        {
            $this->photo_name = uniqid().".".$this->photo_file->guessExtension();
        }
    }

    /**
     * @MongoDB\PostPersist()
     * @MongoDB\PostUpdate()
     */
    public function upload()
    {
        if($this->photo_file === null)
        {
            return;
        }

        if(!file_exists($this->getUploadDir()))
        {
            mkdir($this->getUploadDir(),0777, true);
        }

        $this->photo_file->move($this->getUploadDir(), $this->photo_name);
        unset($this->photo_file);
    }

    /**
     * @MongoDB\PostRemove()
     */
    public function removeUpload()
    {
        if($this->getAbsolutePath() !== null){
            if(file_exists($this->getAbsolutePath()))
            {
                unlink($this->getAbsolutePath());
            }
        }
    }
    /**
     * Get id
     *
     * @return id $id
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set updatedAt
     *
     * @param date $updatedAt
     * @return self
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updated_at = $updatedAt;
        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return date $updatedAt
     */
    public function getUpdatedAt()
    {
        return $this->updated_at;
    }

    /**
     * Set photoName
     *
     * @param string $photoName
     * @return self
     */
    public function setPhotoName($photoName)
    {
        $this->photo_name = $photoName;
        return $this;
    }

    /**
     * Get photoName
     *
     * @return string $photoName
     */
    public function getPhotoName()
    {
        return $this->photo_name;
    }

    public function setPhotoFile($file)
    {
        $this->photo_file = $file;
        return $this;
    }

    public function getPhotoFile()
    {
        return $this->photo_file;
    }

    /**
     * @MongoDB\PrePersist
     */
    public function setUpdatedAtValue()
    {
        $this->setUpdatedAt(new \DateTime());
    }
}

也许这就是php设置的情况?

增加
php.ini
中的
upload\u max\u filesize=2M
值会有所帮助。

您好,我在dropzone上也遇到了问题。看到了吗:谢谢。我以前看过。我已经从中创建了必要的代码。但不幸的是,当我试图上传多个文件时,我总是会遇到这个例外。好的,也许你必须在你的表单中添加:在你的表单中。那么gbr是什么?我认为,你必须在foreach函数中添加flush
<?php
namespace Gbr\BEBundle\Document;

use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * @MongoDB\Document(collection="overview_photos", repositoryClass="Gbr\BEBundle\Repository\OverviewPhotoRepository")
 */
class OverviewPhoto
{
    /**
     * @MongoDB\Id(strategy="AUTO")
     */
    protected $id;

    /**
     * @MongoDB\Date
     */
    protected $updated_at;

    /**
     * @Assert\Image
     */
    protected $photo_file;

    /**
     * @MongoDB\String
     */
    protected $photo_name;


    public function getUploadDir()
    {
        return 'uploads/images/overview/slider';
    }

    public function getRootUploadDir()
    {
        return "/../../../../web/". $this->getUploadDir();
    }

    public function getWebPath()
    {
        return $this->photo_name === null ? null : "/".$this->getUploadDir()."/".$this->photo_name;
    }

    public function getAbsolutePath()
    {
        return $this->photo_name === null ? null : "/".$this->getRootUploadDir()."/".$this->photo_name;
    }

    /**
     * WARNING!! PreUpdate no fired since $file is not managed by Doctrine.
     * SOLUTION: use PostLoad() Event.
     * @MongoDB\PostLoad()
     */
    public function postLoad()
    {
        $this->setUpdatedAt(new \DateTime());
    }

    /**
     * @MongoDB\PrePersist()
     * @MongoDB\PreUpdate()
     */
    public function preUpload()
    {
        if($this->photo_file !== null)
        {
            $this->photo_name = uniqid().".".$this->photo_file->guessExtension();
        }
    }

    /**
     * @MongoDB\PostPersist()
     * @MongoDB\PostUpdate()
     */
    public function upload()
    {
        if($this->photo_file === null)
        {
            return;
        }

        if(!file_exists($this->getUploadDir()))
        {
            mkdir($this->getUploadDir(),0777, true);
        }

        $this->photo_file->move($this->getUploadDir(), $this->photo_name);
        unset($this->photo_file);
    }

    /**
     * @MongoDB\PostRemove()
     */
    public function removeUpload()
    {
        if($this->getAbsolutePath() !== null){
            if(file_exists($this->getAbsolutePath()))
            {
                unlink($this->getAbsolutePath());
            }
        }
    }
    /**
     * Get id
     *
     * @return id $id
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set updatedAt
     *
     * @param date $updatedAt
     * @return self
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updated_at = $updatedAt;
        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return date $updatedAt
     */
    public function getUpdatedAt()
    {
        return $this->updated_at;
    }

    /**
     * Set photoName
     *
     * @param string $photoName
     * @return self
     */
    public function setPhotoName($photoName)
    {
        $this->photo_name = $photoName;
        return $this;
    }

    /**
     * Get photoName
     *
     * @return string $photoName
     */
    public function getPhotoName()
    {
        return $this->photo_name;
    }

    public function setPhotoFile($file)
    {
        $this->photo_file = $file;
        return $this;
    }

    public function getPhotoFile()
    {
        return $this->photo_file;
    }

    /**
     * @MongoDB\PrePersist
     */
    public function setUpdatedAtValue()
    {
        $this->setUpdatedAt(new \DateTime());
    }
}