1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
<?php
/**
* Copyright (c) STMicroelectronics, 2004-2009. All rights reserved
*
* This file is a part of Codendi.
*
* Codendi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Codendi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Codendi. If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'ForumML_AttachmentDao.class.php';
class ForumML_Attachment {
private $_dao;
function getById($id) {
$attach = null;
$dar = $this->getDao()->getById($id);
if ($dar && !$dar->isError()) {
$attch = $dar->current();
$attch['type'] = $this->getType($attch);
}
return $attch;
}
/**
* Return attachment mime type
*
* Try to get it from the db and if it fails, try with filename
*/
function getType($row) {
/*if (preg_match('/^[ ]*(.*\/.*)[ ]*;?.*$/', $row['file_type'], $matches)) {
$type = $matches[1];
} else {
// Retrieve the uploaded file type
switch(strtoupper(strrchr($row['file_name'], "."))) {
case ".GZ":
$type = "application/x-gzip";
break;
case ".TGZ":
$type = "application/x-gzip";
break;
case ".ZIP":
$type = "application/zip";
break;
case ".PDF":
$type = "application/pdf";
break;
case ".PNG":
$type = "image/png";
break;
case ".GIF":
$type = "image/gif";
break;
case ".JPG":
$type = "image/jpeg";
break;
case ".TXT":
$type = "text/plain";
break;
case ".HTM":
$type = "text/html";
break;
case ".HTML":
$type = "text/html";
break;
default:
$type = "application/octet-stream";
break;
}
}
return $type;*/
return mime_content_type($row['file_path']);
}
function getDao() {
if (!isset($this->_dao)) {
$this->_dao = new ForumML_AttachmentDao(CodendiDataAccess::instance());
}
return $this->_dao;
}
}
|