Attachment/AttachmentHandler.php
public function storeAndAttachFile(File $file, AttachableObjectInterface $object, $fieldName = null, $deleteAfterCopy = null, $customFilename = null)
    {
        $this->checkAttachableObject($object);
        
        if (null === $deleteAfterCopy)
        {
            $deleteAfterCopy = $this->guessDeleteAfterCopy($file, $object, $fieldName);
        }
        
        $this->checkFile($file, $deleteAfterCopy);
        
        $fileKey = $this->generateKey($file, $object, $fieldName);
        $this->copyToStorage($file, $fileKey);
        
        $attachment = $this->saveToDatabase($file, $object, $fieldName, $fileKey, $customFilename);
        
        if ($deleteAfterCopy)
        {
            unlink($file->getRealPath());
        }
        
        return $attachment;
    }
public function storeAndAttachFile(File $file, AttachableObjectInterface $object, $fieldName = null, $deleteAfterCopy = null, $customFilename = null)
    {
        $this->checkAttachableObject($object);
        
        if (null === $deleteAfterCopy)
        {
            $deleteAfterCopy = $this->guessDeleteAfterCopy($file, $object, $fieldName);
        }
        
        $this->checkFile($file, $deleteAfterCopy);
        
        $fileKey = $this->generateKey($file, $object, $fieldName);
        $this->copyToStorage($file, $fileKey);
        
        $attachment = $this->saveToDatabase($file, $object, $fieldName, $fileKey, $customFilename);
        
        if ($deleteAfterCopy)
        {
            unlink($file->getRealPath());
        }
        
        return $attachment;
    }
public function storeAndAttachFile ( File $ file , AttachableObjectInterface $ object , $ fieldName = null , $ deleteAfterCopy = null , $ customFilename = null ) { $ this -> checkAttachableObject ( $ object ) ; if ( null === $ deleteAfterCopy ) { $ deleteAfterCopy = $ this -> guessDeleteAfterCopy ( $ file , $ object , $ fieldName ) ; } $ this -> checkFile ( $ file , $ deleteAfterCopy ) ; $ fileKey = $ this -> generateKey ( $ file , $ object , $ fieldName ) ; $ this -> copyToStorage ( $ file , $ fileKey ) ; $ attachment = $ this -> saveToDatabase ( $ file , $ object , $ fieldName , $ fileKey , $ customFilename ) ; if ( $ deleteAfterCopy ) { unlink ( $ file -> getRealPath ( ) ) ; } return $ attachment ; }
Store a new attachment file for the given object and optional object field name.
There is no need for the field name to exist explicitly inside the object.

@throws InputFileNotReadableException
@throws InputFileNotWritableException
@throws CouldNotWriteToStorageException

@param File $file
@param AttachableObjectInterface $object
@param string $fieldName
@param boolean $deleteAfterCopy  Override default file deletion behavior
@param string $customFilename    Optional custom file name to use for the created link

@return Attachment   The created Attachment object
Store a new attachment file for the given object and optional object field name . There is no need for the field name to exist explicitly inside the object .