CMSMS FormBuilder Version: 0.9 Attachments Don’t Delete

CMS Made Simple
While working on a CMS Made Simple site for a client, we ran into an issue with uploaded files to be used as email attachments not being deleted after the email is sent.

This applies to their CMSMS FormBuilder Module Version 0.6.

The issue was in how the code in cmsms_root/modules/FormBuilder/classes/FileUploadField.class.php was not implemented properly. ┬áHere’s the replacement function you can use instead of the original PostDispositionAction() function, to make it work properly.

function PostDispositionAction()
     {
          global $gCms;
 
          if ($this->GetOption('remove_file','0') == '1')
          {
               $dest = $this -> GetHumanReadableValue(true);
               if(is_array($this->Value) && !empty($this->Value[0])){
                    $dest=$this->Value[0];
               }
               elseif(!empty($this->Value)){
                    $dest=$this->Value;
               }
 
               if($dest){
                    $path = $this->GetOption('file_destination');
                    $dest = cms_join_path($path, $dest);
                    if (file_exists($dest)) {
                         unlink($dest);                         
                    }                    
               }               
          }
     }

Hope this helps someone!

Leave a Reply

Your email address will not be published. Required fields are marked *