public function testOdt() { $mime = Kwf_Uploads_Row::detectMimeType(false, file_get_contents(KWF_PATH . '/tests/Kwf/Uploads/DetectMimeType/sample.odt')); $this->assertEquals($mime, 'application/vnd.oasis.opendocument.text'); }
private static function _fileinfo() { if (!function_exists('finfo_file')) { return array('status' => self::RESULT_WARNING, 'message' => "Extension 'fileinfo' is not loaded"); } try { $mime = Kwf_Uploads_Row::detectMimeType(false, file_get_contents(KWF_PATH . '/images/information.png')); if ($mime != 'image/png') { return array('status' => self::RESULT_WARNING, 'message' => "fileinfo returned wrong information: {$mime}"); } $mime = Kwf_Uploads_Row::detectMimeType(false, file_get_contents(KWF_PATH . '/Kwf/Util/Check/Config/sample.docx')); if (!($mime == 'application/msword' || $mime == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')) { return array('status' => self::RESULT_WARNING, 'message' => "fileinfo returned wrong information: {$mime}"); } $mime = Kwf_Uploads_Row::detectMimeType(false, file_get_contents(KWF_PATH . '/Kwf/Util/Check/Config/sample.odt')); if ($mime != 'application/vnd.oasis.opendocument.text') { return array('status' => self::RESULT_WARNING, 'message' => "fileinfo returned wrong information: {$mime}"); } } catch (Exception $e) { return array('status' => self::RESULT_WARNING, 'message' => "fileinfo failed: " . $e->getMessage()); } return array('status' => self::RESULT_OK); }
private function _saveAttachmentData($file, $mailFilename = null, $mimeType = null) { $attachRow = $this->createChildRow('Attachments'); $attachRow->is_upload = 0; // die datei in einen uploads unterordner kopieren, könnte ja // zwischendurch mal geloescht werden $copyDir = $this->getModel()->getAttachmentSaveFolder(); if ($file instanceof Zend_Mime_Part) { $fileContent = $file->getContent(); if ($file->encoding == Zend_Mime::ENCODING_BASE64) { $fileContent = base64_decode($fileContent); } else { throw new Kwf_Exception_NotYetImplemented("File encoding type '" . $file->encoding . "' not supported yet"); } $fileMd5 = md5($file->getContent()); $newFilepath = $copyDir . '/' . $fileMd5; if (!file_exists($newFilepath)) { file_put_contents($newFilepath, $fileContent); } $attachRow->mail_filename = $file->filename; $attachRow->mime_type = $file->type; if ($file->id) { $attachRow->cid = $file->id; } } else { $fileMd5 = md5_file($file); $newFilepath = $copyDir . '/' . $fileMd5; if (!file_exists($newFilepath)) { copy($file, $newFilepath); } $attachRow->mail_filename = !is_null($mailFilename) ? $mailFilename : basename($file); $attachRow->mime_type = !is_null($mimeType) ? $mimeType : Kwf_Uploads_Row::detectMimeType(false, file_get_contents($newFilepath)); } $attachRow->filename = $fileMd5; $attachRow->save(); }