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;
        }
    }
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;
        }
    }
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 ; } }
afterSave Event. If an attachment entity has its tmpPath value set, it will be moved
to the defined filepath

@param Event $event Event
@param Attachment $attachment Entity
@param ArrayObject $options Options
@return void
@throws \Exception If the file couldn't be moved
afterSave Event . If an attachment entity has its tmpPath value set it will be moved to the defined filepath