Note that there are some explanatory texts on larger screens.

plurals
  1. POIntegrate Dropzone with Symfony2 giving file "" does not exist
    primarykey
    data
    text
    <p>I'm trying to integrate Dropzone with symfony. But when I select more than <strong>one</strong> file, I get this exception:</p> <pre><code> 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 -&gt;guess ('') in /var/www/thegabrielhotel/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/File/File.php at line 87 + at File -&gt;getMimeType () in /var/www/thegabrielhotel/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/File/File.php at line 64 + at File -&gt;guessExtension () in /var/www/thegabrielhotel/src/Gbr/BEBundle/Document/OverviewPhoto.php at line 71 + at OverviewPhoto -&gt;preUpload () in /var/www/thegabrielhotel/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php at line 525 + at ClassMetadataInfo -&gt;invokeLifecycleCallbacks ('prePersist', object(OverviewPhoto)) in /var/www/thegabrielhotel/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php at line 953 + at UnitOfWork -&gt;persistNew (object(ClassMetadata), object(OverviewPhoto)) in /var/www/thegabrielhotel/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php at line 1775 + at UnitOfWork -&gt;doPersist (object(OverviewPhoto), array('000000001f48b19e00007fd7abcd7e2a' =&gt; object(OverviewPhoto))) in /var/www/thegabrielhotel/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php at line 1739 + at UnitOfWork -&gt;persist (object(OverviewPhoto)) in /var/www/thegabrielhotel/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/DocumentManager.php at line 384 + at DocumentManager -&gt;persist (object(OverviewPhoto)) in /var/www/thegabrielhotel/src/Gbr/BEBundle/Controller/DefaultController.php at line 57 + at DefaultController -&gt;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 -&gt;handleRaw (object(Request), '1') in kernel.root_dir/bootstrap.php.cache at line 2817 + at HttpKernel -&gt;handle (object(Request), '1', true) in kernel.root_dir/bootstrap.php.cache at line 2946 + at ContainerAwareHttpKernel -&gt;handle (object(Request), '1', true) in kernel.root_dir/bootstrap.php.cache at line 2248 + at Kernel -&gt;handle (object(Request)) in /var/www/thegabrielhotel/web/app_dev.php at line 28 + </code></pre> <p>Here's my layout part of dropzone:</p> <pre><code>&lt;form action="{{ path("gbr_be_post_overview_photos") }}" class="dropzone" id="my-dropzone"&gt; &lt;/form&gt; </code></pre> <p>And here's my <code>postOverviewPhotosAction</code> post action:</p> <pre><code>public function postOverviewPhotosAction(Request $request) { $dm = $this-&gt;get("doctrine_mongodb")-&gt;getManager(); $files = $request-&gt;files; foreach($files as $file) { $overview_photo = new OverviewPhoto(); $overview_photo-&gt;setPhotoFile($file); $dm-&gt;persist($overview_photo); } $dm-&gt;flush(); return $this-&gt;render($this-&gt;generateUrl("gbr_be_get_overview")); } </code></pre> <p>And <code>OverviewPhoto</code> document:</p> <pre><code>&lt;?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-&gt;getUploadDir(); } public function getWebPath() { return $this-&gt;photo_name === null ? null : "/".$this-&gt;getUploadDir()."/".$this-&gt;photo_name; } public function getAbsolutePath() { return $this-&gt;photo_name === null ? null : "/".$this-&gt;getRootUploadDir()."/".$this-&gt;photo_name; } /** * WARNING!! PreUpdate no fired since $file is not managed by Doctrine. * SOLUTION: use PostLoad() Event. * @MongoDB\PostLoad() */ public function postLoad() { $this-&gt;setUpdatedAt(new \DateTime()); } /** * @MongoDB\PrePersist() * @MongoDB\PreUpdate() */ public function preUpload() { if($this-&gt;photo_file !== null) { $this-&gt;photo_name = uniqid().".".$this-&gt;photo_file-&gt;guessExtension(); } } /** * @MongoDB\PostPersist() * @MongoDB\PostUpdate() */ public function upload() { if($this-&gt;photo_file === null) { return; } if(!file_exists($this-&gt;getUploadDir())) { mkdir($this-&gt;getUploadDir(),0777, true); } $this-&gt;photo_file-&gt;move($this-&gt;getUploadDir(), $this-&gt;photo_name); unset($this-&gt;photo_file); } /** * @MongoDB\PostRemove() */ public function removeUpload() { if($this-&gt;getAbsolutePath() !== null){ if(file_exists($this-&gt;getAbsolutePath())) { unlink($this-&gt;getAbsolutePath()); } } } /** * Get id * * @return id $id */ public function getId() { return $this-&gt;id; } /** * Set updatedAt * * @param date $updatedAt * @return self */ public function setUpdatedAt($updatedAt) { $this-&gt;updated_at = $updatedAt; return $this; } /** * Get updatedAt * * @return date $updatedAt */ public function getUpdatedAt() { return $this-&gt;updated_at; } /** * Set photoName * * @param string $photoName * @return self */ public function setPhotoName($photoName) { $this-&gt;photo_name = $photoName; return $this; } /** * Get photoName * * @return string $photoName */ public function getPhotoName() { return $this-&gt;photo_name; } public function setPhotoFile($file) { $this-&gt;photo_file = $file; return $this; } public function getPhotoFile() { return $this-&gt;photo_file; } /** * @MongoDB\PrePersist */ public function setUpdatedAtValue() { $this-&gt;setUpdatedAt(new \DateTime()); } } </code></pre> <p>Any help would be appreciated. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload