file_path)) { return false; } $this->filePath = $this->file_path; if (@file_exists($this->file_path)) { return $this->filePath; } return $this->filePath; } /** * Sets the file path. * * @param string $filePath File path incl. file name and optional extension * * @return void */ public function setFilePath($filePath) { $this->file_path = $filePath; } /** * Sets the data part info. * * @param DataPartInfo $dataInfo Date info (file content) * * @return void */ public function addDataPartInfo(DataPartInfo $dataInfo) { $this->dataInfo = $dataInfo; } /** * Gets the MIME type. * * @return string */ public function getMimeType() { if (!$this->mimeType) { if (class_exists('finfo')) { $finfo = new finfo(FILEINFO_MIME); $this->mimeType = $finfo->buffer($this->getContents()); } } return $this->mimeType; } /** * Gets the file content. * * @return string */ public function getContents() { return $this->dataInfo->fetch(); } /** * Saves the attachment object on the disk. * * @return bool True, if it could save the attachment on the disk */ public function saveToDisk() { if (null === $this->dataInfo) { return false; } if (false === file_put_contents($this->filePath, $this->dataInfo->fetch())) { unset($this->filePath); unset($this->file_path); return false; } return true; } }