Source for file binfileclass.php

Documentation is available at binfileclass.php


1 <?php
2 /**
3 * @author Jan H. Andersen <jha@ipwsystems.dk>
4 * @author Martin R. Larsen <mrl@ipwsystems.dk>
5 * @copyright {@link http://www.ipwsystems.dk/ IPW Systems a.s}
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
7 * @package METAjour
8 * @subpackage core
9 * $Id: binfileclass.php,v 1.12 2005/02/07 09:56:20 jan Exp $
10 */
11
12 require_once('absfileclass.php');
13
14 class binfile extends absfile {
15 var $ERR_CANNOTMAKEDIR = 8;
16
17 function binfile() {
18 $this->absfile();
19 $this->addcolumn('name',0,UI_STRING);
20 $this->addcolumn('mimetype',0,UI_HIDDEN);
21 $this->addcolumn('description',0,UI_STRING);
22 $this->addcolumn('revision',0,UI_HIDDEN);
23
24 $this->removeview('createvariant');
25 }
26
27 function stdListInfocol() {
28 $result = parent::stdListInfocol();
29 $result[] = '_icon';
30 return $result;
31 }
32
33 function stdListCol() {
34 $result[] = 'name';
35 $result[] = 'description';
36 $result[] = 'createdbyname';
37 $result[] = 'changed';
38 return $result;
39 }
40
41 function getRoot() {
42 return $this->userhandler->getDirBinfile();
43 }
44
45 function prv_createobject(&$arr) {
46 $uploaddir = $this->getRoot();
47 $uploadfile = $uploaddir .substr($this->getObjectId(),-2).'/'. $this->getObjectId();
48 if (!file_exists($uploaddir .substr($this->getObjectId(),-2).'/')) {
49 if(!@mkdir($uploaddir .substr($this->getObjectId(),-2).'/', 0755)) {
50 $this->errorcode = $this->ERR_CANNOTMAKEDIR;
51 return $this->errorcode;
52 }
53 }
54 if ($_FILES['__uploadfile__']['tmp_name']) {
55 if (move_uploaded_file($_FILES['__uploadfile__']['tmp_name'], $uploadfile)) {
56 $arr['name'] = $_FILES['__uploadfile__']['name'];
57 $arr['mimetype'] = $_FILES['__uploadfile__']['type'];
58 }
59 } elseif($arr['realfile']) {
60 copy($arr['realfile'],$uploadfile);
61 } elseif($arr['_makecontent_']) {
62 if ($handle = fopen($uploadfile, 'w')) {
63 fwrite($handle, $arr['_makecontent_']);
64 fclose($handle);
65 }
66 }
67
68 parent::prv_createobject($arr);
69 }
70
71 function prv_readobject($objectid) {
72 $uploaddir = $this->getRoot();
73 $res['realfile'] = $uploaddir .substr($objectid,-2).'/'. $objectid;
74 return $res;
75 }
76
77 function prv_updateobject($objectid, $arr) {
78 $uploaddir = $this->getRoot();
79 $uploadfile = $uploaddir .substr($objectid,-2).'/'. $objectid;
80 if (!file_exists($uploaddir .substr($objectid,-2).'/')) {
81 if(!@mkdir($uploaddir .substr($objectid,-2).'/', 0755)) {
82 $this->errorcode = $this->ERR_CANNOTMAKEDIR;
83 return $this->errorcode;
84 }
85 }
86 if ($_FILES['__uploadfile__']['tmp_name']) {
87 rename($uploadfile,$uploadfile.".".$arr['revision']);
88 $arr['revision'] = $arr['revision'] + 1;
89 if (move_uploaded_file($_FILES['__uploadfile__']['tmp_name'], $uploadfile)) {
90 $arr['mimetype'] = $_FILES['__uploadfile__']['type'];
91 }
92 }
93
94 parent::prv_updateobject($objectid, $arr);
95 }
96
97 function GetRevisions() {
98 $objectid = $this->elements[0]['objectid'];
99 $uploaddir = $this->getRoot();
100 $uploadfile = $uploaddir .substr($objectid,-2).'/'. $objectid;
101 $result = array();
102 $files = glob($uploadfile.".*");
103 if (is_array($files)) {
104 foreach ($files as $filename) {
105 $a = pathinfo($filename);
106 $result[] = $a['extension'];
107 }
108 }
109 return $result;
110 }
111
112 }
113
114 ?>

Documentation generated on Thu, 9 Jun 2005 06:51:34 +0200 by phpDocumentor 1.2.3