3 * Copyright (c) STMicroelectronics, 2004-2009. All rights reserved
5 * This file is a part of Codendi.
7 * Codendi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Codendi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
21 require_once 'ForumML_AttachmentDao.class.php';
23 class ForumML_Attachment {
26 function getById($id) {
28 $dar = $this->getDao()->getById($id);
29 if ($dar && !$dar->isError()) {
30 $attch = $dar->current();
31 $attch['type'] = $this->getType($attch);
37 * Return attachment mime type
39 * Try to get it from the db and if it fails, try with filename
41 function getType($row) {
42 /*if (preg_match('/^[ ]*(.*\/.*)[ ]*;?.*$/', $row['file_type'], $matches)) {
45 // Retrieve the uploaded file type
46 switch(strtoupper(strrchr($row['file_name'], "."))) {
48 $type = "application/x-gzip";
51 $type = "application/x-gzip";
54 $type = "application/zip";
57 $type = "application/pdf";
78 $type = "application/octet-stream";
83 return mime_content_type($row['file_path']);
87 if (!isset($this->_dao)) {
88 $this->_dao = new ForumML_AttachmentDao(CodendiDataAccess::instance());