Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>if you want to remove the image try this </p> <pre><code>public function deleteimgAction(image $image) { $em = $this-&gt;getDoctrine()-&gt;getEntityManager(); $em-&gt;remove($image); $em-&gt;flush(); return $this-&gt;redirect($this-&gt;generateUrl('rederect..')); } </code></pre> <p>and in the image entity you add the have cyclecallback to add an automatical trigger that delete the image when you delete the recorde in the database </p> <pre><code>/** * Image * @ORM\HasLifecycleCallbacks * @ORM\Table(name="image") * @ORM\Entity(repositoryClass="Elite\AdminBundle\Entity\ImageRepository") */ class Image { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * @Assert\File(maxSize="6000000") * @ORM\Column(name="image", type="string", length=255) */ private $image; /** * Get id * * @return integer */ public function getId() { return $this-&gt;id; } /** * Set image * * @param string $image * @return Image */ public function setImage($image) { $this-&gt;image = $image; return $this; } /** * Get image * * @return string */ public function getImage() { return $this-&gt;image; } public function getFullImagePath() { return null === $this-&gt;image ? null : $this-&gt;getUploadRootDir(). $this-&gt;image; } protected function getUploadRootDir() { // the absolute directory path where uploaded documents should be saved return $this-&gt;getTmpUploadRootDir(). $this-&gt;getAlbum() ."/"; } protected function getTmpUploadRootDir() { // the absolute directory path where uploaded documents should be saved return __DIR__ . '/../../../../web/upload/albums/'; } /** * @ORM\PrePersist() * @ORM\PreUpdate() */ public function uploadImage() { // the file property can be empty if the field is not required if (null === $this-&gt;image) { return; } $name=preg_replace('/[^\w\._]+/', '_',$this-&gt;image-&gt;getClientOriginalName()); if(!$this-&gt;id){ $this-&gt;image-&gt;move($this-&gt;getTmpUploadRootDir(), $name); }else{ $this-&gt;image-&gt;move($this-&gt;getUploadRootDir(), $name); } $this-&gt;setImage($name); } /** * @ORM\PostPersist() */ public function moveImage() { if (null === $this-&gt;image) { return; } if(!is_dir($this-&gt;getUploadRootDir())){ mkdir($this-&gt;getUploadRootDir()); } copy($this-&gt;getTmpUploadRootDir().$this-&gt;image, $this-&gt;getFullImagePath()); $fullimage=$this-&gt;getFullImagePath(); $filename="$fullimage"; $parts=pathinfo($filename); $ext=$parts['extension']; if($ext == 'jpg' or $ext == 'jpeg'){ $img = imagecreatefromjpeg($filename); header("Content-Type: image/jpeg"); imagejpeg($img, $filename, 70); } if($ext == 'png'){ $img = imagecreatefrompng($filename); imagealphablending($img, true); imagesavealpha($img, true); header("Content-Type: image/png"); imagepng($img, $filename, 8); } unlink($this-&gt;getTmpUploadRootDir().$this-&gt;image); } /** * @ORM\PreRemove() */ public function removeImage() { unlink($this-&gt;getFullImagePath()); } } </code></pre>
 

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