public function afterSave(Event $event, Attachment $attachment, \ArrayObject $options)
    {
        if ($attachment->tmpPath) {
            // Make sure the folder is created
            $folder = new Folder();
            $targetDir = Configure::read('Attachments.path') . dirname($attachment->filepath);

            if (!$folder->create($targetDir)) {
                throw new \Exception("Folder {$targetDir} could not be created.");
            }
            $targetPath = Configure::read('Attachments.path') . $attachment->filepath;
            if (!rename($attachment->tmpPath, $targetPath)) {
                throw new \Exception("Temporary file {$attachment->tmpPath} could not be moved to {$attachment->filepath}");
            }
            $attachment->tmpPath = null;
        }
    }