The file '/tmp/phpAtfqKp' does not exist when uploading Image using Symfony2 Sonata Admin Bundle
<p>I hope you're doing well.</p>

<p>Can anyone help me with this error ? I'm trying to upload an image using doctrine, after the image is uploaded I get <strong>The file "/tmp/phpAtfqKp" does not exist</strong>. I'm using sonata admin bundle to create the entity.
I know that the image is uploaded because it is found in <strong>web/uploads/property</strong> and when going to the edit entity page all images are displayed without any problem.</p>

<p>Here is my Image entity:</p>

<pre><code>&lt;?php

namespace Hatch2Web\MainBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
use Hatch2Web\MainBundle\Service\UrlService;

/**
 * Images
 *
 * @ORM\Table(name="image")
 * @ORM\Entity(repositoryClass="Hatch2Web\MainBundle\Repository\ImagesRepository")
 * @ORM\HasLifecycleCallbacks()
 */
class Image
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

/**
 * @var string
 *
 * @ORM\Column(name="name", type="string", length=255,nullable=true)
 */
private $name;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="created_at", type="datetime")
 */
private $createdAt;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="updated_at", type="datetime", nullable=true)
 */
private $updated_at;

/**
 * @ORM\ManyToOne(targetEntity="Hatch2Web\MainBundle\Entity\Property", inversedBy="images")
 */
private $property;


/**
 * @Assert\File(maxSize="50000000",
 *     mimeTypes = {"image/jpeg", "image/jpg","image/png", "image/gif", "image/x-ms-bmp"},
 *     mimeTypesMessage = "Please upload a valid Mime Type File")
 *
 */
public $file;


/**
 *
 *
 * string
 */
private $dummyUrl;


public function __construct()
{
    $this-&gt;createdAt = new \DateTime();
}


/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this-&gt;id;
}

/**
 * Set name
 *
 * @param string $name
 * @return Image
 */
public function setName($name)
{
    $this-&gt;name = $name;

    return $this;
}

/**
 * Get name
 *
 * @return string
 */
public function getName()
{
    return $this-&gt;name;
}

/**
 * Set createdAt
 *
 * @param \DateTime $createdAt
 * @return Image
 */
public function setCreatedAt($createdAt)
{
    $this-&gt;createdAt = $createdAt;

    return $this;
}

/**
 * Get createdAt
 *
 * @return \DateTime
 */
public function getCreatedAt()
{
    return $this-&gt;createdAt;
}

/**
 * Set property
 *
 * @param \Hatch2Web\MainBundle\Entity\Property $property
 * @return Image
 */
public function setProperty(\Hatch2Web\MainBundle\Entity\Property $property = null)
{
    $this-&gt;property = $property;

    return $this;
}

/**
 * Get property
 *
 * @return \Hatch2Web\MainBundle\Entity\Property
 */
public function getProperty()
{
    return $this-&gt;property;
}



/** File  Upload  */


/**
 * Get file.
 *
 * @return UploadedFile
 */
public function getFile()
{
    return $this-&gt;file;
}


public function getUploadDir()
{
    return 'uploads/properties';
}


/**
 * Sets file.
 *
 * @param UploadedFile $file
 */
public function setFile(UploadedFile $file = null, $hash)
{
    if ($file) {
        $this-&gt;file = $file;
        $this-&gt;name = $hash . "." . $file-&gt;guessExtension();
    }

}


public function getDummyUrl()
{

    $object = new UrlService();
    $baseUrl = $object-&gt;getBaseUrl();
    if ($this-&gt;getName()) {
        return $baseUrl . $this-&gt;getUploadDir() . '/' . $this-&gt;getName();
    }
    return $object-&gt;getNoImage();

}

/**
 * @return mixed
 */
public function getUpdatedAt()
{
    return $this-&gt;updated_at;
}

/**
 * @param mixed $updated_at
 */
public function setUpdatedAt($updated_at)
{
    $this-&gt;updated_at = $updated_at;
}

/**
 * @ORM\PrePersist()
 * @ORM\PreUpdate()
 */
public function preUpload()
{
    if (null !== $this-&gt;getFile()) {

        $filename = sha1($this-&gt;getFile()-&gt;getClientOriginalName());
        $this-&gt;name = $filename . '.' . $this-&gt;getFile()-&gt;guessExtension();

    }
}

/**
 * @ORM\PostPersist()
 * @ORM\PostUpdate()
 */
public function upload()
{
    if (null === $this-&gt;getFile()) {
        return;
    }
    $this-&gt;getFile()-&gt;move($this-&gt;getUploadDir(), $this-&gt;name);

    $this-&gt;file = null;
}

/**
 * Lifecycle callback to upload the file to the server
 */
public function lifecycleFileUpload()
{
    $this-&gt;upload();
}

/**
 * @ORM\PreRemove()
 *
 *
 *
 */
public function removeFile()
{
    $url = $this-&gt;getUploadDir() . '/' . $this-&gt;getName();

    try {
        if (file_exists($url)) {
            unlink($url);
        }
    } catch (\Exception $e) {
        return $e-&gt;getMessage();
    }
}

/**
 * Updates the hash value to force the preUpdate and postUpdate events to fire
 */
public function refreshUpdated()
{
    $this-&gt;setUpdatedAt(new \DateTime());
}
}
</code></pre>

<p>And here is a screenshot
<a href="https://i.stack.imgur.com/pbbfG.png" rel="nofollow">enter image description here</a></p>