Showing results for 
Search instead for 
Did you mean: 

dropzone.js edit (add/delete) pre-exisitng image files in Magento

dropzone.js edit (add/delete) pre-exisitng image files in Magento



Below is my code for deleting images when clicked on "remove file" CTA on the dropzonejs box. However, when the "remove file" is clicked, only the thumbnail image is deleted, and not the actual file.

By calling the delete function in Magento through Ajax when the "removedfile" is called, it should delete the thumbnail as well as the file, but it does not seem to work as the server still keeps the pre-loaded image file.


this.on("removedfile", function(file) {
         url: "<?php echo Mage::getUrl("*/*/deleteimage"); ?>",
         type: "POST",
         dataType: "json",
         data: {'pid': "<?php echo $loadpro->getId(); ?>",'file'},
     success: function (data) {
            Success = true;//doesnt goes here
        error: function (textStatus, errorThrown) {
          var det = checkfile('<?php echo $loadpro->getId(); ?>');

          if(det != null)
              maxcount = 1;
          else {
            maxcount = null;


Below is the code for the Magento controller that is called in the function above that listens for the "removedfile."


public function deleteimageAction()
    $id= $this->getRequest()->getParam('pid');
    $imagename= $this->getRequest()->getParam('file');
    $product = Mage::getModel('catalog/product')->load($id);

    $productMediaConfig = Mage::getModel('catalog/product_media_config');
    $mediaGallery = $product->getMediaGalleryImages();

    foreach($mediaGallery as $mediagg){
      $file = $mediagg->getUrl();
      $fileName = basename($file);
      if($fileName == $imagename){
         $filepath = $mediagg->getFile();

      $newimage = '';
      $data= $this->getRequest()->getParams();
      //error_log(print_r($data, TRUE));
      $_product = Mage::getModel('catalog/product')->load($data['pid'])->getMediaGalleryImages();
      $main = explode('/',$filepath);
      foreach($_product as $_image) {
        $arr = explode('/',$_image['path']);
        if(array_pop($arr) != array_pop($main)){
          $newimage = $_image['file'];
          $id = $_image['value_id'];
      $mediaApi = Mage::getModel("catalog/product_attribute_media_api");
    } catch (Exception $e) {
             $this->getResponse()->setHeader('Content-type', 'text/html');

I have tried most of the methods that are in google, as well as stackoverflow, but could not find an answer that works in this case.

If you know a solution to this problem, please let me know.