Swift_Mime_Attachment::setFile PHP Method

setFile() public method

Set the file that this attachment is for.
public setFile ( Swift_FileStream $file, string $contentType = null ) : Swift_Mime_Attachment
$file Swift_FileStream
$contentType string optional
return Swift_Mime_Attachment
    public function setFile(Swift_FileStream $file, $contentType = null)
    {
        $this->setFilename(basename($file->getPath()));
        $this->setBody($file, $contentType);
        if (!isset($contentType)) {
            $extension = strtolower(substr($file->getPath(), strrpos($file->getPath(), '.') + 1));
            if (array_key_exists($extension, $this->_mimeTypes)) {
                $this->setContentType($this->_mimeTypes[$extension]);
            }
        }
        return $this;
    }