Framework  3.9
DocumentHandler Class Reference

Public Member Functions

 DocumentHandler ()
 
 getDocMimeType ($name)
 Replaces getMimeType because name conflicts with getMIMEType. More...
 

Static Public Member Functions

static getDocType ($doc)
 Returns a human-readable type name for a document, based on the file extension of the supplied file name. More...
 
static getDocSize ($doc)
 Returns the file size in Kb for a document. More...
 
static getDocIcon ($doc)
 
static getIcon ($file)
 Retrieves a graphic icon appropriate for the given file. More...
 
static getMIMEType ($filename)
 

Detailed Description

Definition at line 113 of file document_handler.inc.

Member Function Documentation

◆ DocumentHandler()

DocumentHandler::DocumentHandler ( )

Definition at line 115 of file document_handler.inc.

116  {
117 
118  }

◆ getDocIcon()

static DocumentHandler::getDocIcon (   $doc)
static

Definition at line 189 of file document_handler.inc.

190  {
191  global $doc_icons;
192  $n = strtolower($doc);
193  $extension = substr($n, strrpos($n, "."));
194  $icon = $doc_icons[$extension];
195  if (!$icon) $icon = "/fakoli/images/file_icon.png";
196  return $icon;
197  }
$doc_icons

◆ getDocMimeType()

DocumentHandler::getDocMimeType (   $name)

Replaces getMimeType because name conflicts with getMIMEType.

Parameters
$name

Definition at line 178 of file document_handler.inc.

179  {
180  global $doc_mime_types;
181 
182  $n = strtolower($name);
183  $extension = substr($n, strrpos($n, "."));
184  $type = $doc_mime_types[$extension];
185  if (!$type) $type="application/octet-stream";
186  return $type;
187  }
$doc_mime_types

◆ getDocSize()

static DocumentHandler::getDocSize (   $doc)
static

Returns the file size in Kb for a document.

Parameters
string$docthe (local) URL of the document

Definition at line 147 of file document_handler.inc.

148  {
149  global $config;
150 
151  // Find the file name for the file on disk
152 
153  $doc_file = $doc;
154 
155  $doc_file = str_replace($config["uploadurl"], $config["uploaddir"], $doc_file);
156 
157  // If the file exists, return its size
158 
159  if (file_exists($doc_file))
160  {
161  $doc_size = (int)(filesize($doc_file)/1024);
162  }
163  else
164  {
165  $doc_size = 0;
166  }
167 
168  return $doc_size;
169  }

◆ getDocType()

static DocumentHandler::getDocType (   $doc)
static

Returns a human-readable type name for a document, based on the file extension of the supplied file name.

Parameters
string$docthe filename of the document

Definition at line 126 of file document_handler.inc.

127  {
128  global $doc_extensions;
129 
130  $d = strtolower($doc);
131 
132  $ext = substr($d, strrpos($d, "."));
133 
134  $doc_type = $doc_extensions[$ext];
135 
136  if (!$doc_type) $doc_type = "Unknown";
137 
138  return $doc_type;
139  }
$doc_extensions
Mapping of common file extensions to human-readable document type.

◆ getIcon()

static DocumentHandler::getIcon (   $file)
static

Retrieves a graphic icon appropriate for the given file.

Parameters
$filethe name of the file
Returns
string URL of the graphic icon for the file

Definition at line 204 of file document_handler.inc.

205  {
206  global $_icons;
207  global $auto_form_defaults;
208 
209  $ext = substr($file, strrpos($file, "."));
210  $icon = $_icons[$ext];
211  trace("getIcon($file) $ext $icon", 3);
212 
213  if (!isset($icon))
214  {
215  $icon = $_icons["default"];
216  }
217 
218  return $auto_form_defaults["componentPath"].$icon;
219  }
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010
$_icons
Definition: functions.inc:1138

◆ getMIMEType()

static DocumentHandler::getMIMEType (   $filename)
static

Definition at line 221 of file document_handler.inc.

222  {
223  $mime_types = array(
224 
225  'txt' => 'text/plain',
226  'htm' => 'text/html',
227  'html' => 'text/html',
228  'css' => 'text/css',
229  'js' => 'application/javascript',
230  'json' => 'application/json',
231  'xml' => 'application/xml',
232  'swf' => 'application/x-shockwave-flash',
233  'flv' => 'video/x-flv',
234 
235  // images
236  'png' => 'image/png',
237  'jpe' => 'image/jpeg',
238  'jpeg' => 'image/jpeg',
239  'jpg' => 'image/jpeg',
240  'gif' => 'image/gif',
241  'bmp' => 'image/bmp',
242  'ico' => 'image/vnd.microsoft.icon',
243  'tiff' => 'image/tiff',
244  'tif' => 'image/tiff',
245  'svg' => 'image/svg+xml',
246  'svgz' => 'image/svg+xml',
247 
248  // archives
249  'zip' => 'application/zip',
250  'rar' => 'application/x-rar-compressed',
251  'exe' => 'application/x-msdownload',
252  'msi' => 'application/x-msdownload',
253  'cab' => 'application/vnd.ms-cab-compressed',
254 
255  // audio/video
256  'mp3' => 'audio/mpeg',
257  'qt' => 'video/quicktime',
258  'mov' => 'video/quicktime',
259  'mp4' => 'video/mp4',
260  'm4a' => 'audio/m4a',
261 
262  // adobe
263  'pdf' => 'application/pdf',
264  'psd' => 'image/vnd.adobe.photoshop',
265  'ai' => 'application/postscript',
266  'eps' => 'application/postscript',
267  'ps' => 'application/postscript',
268 
269  // ms office
270  'doc' => 'application/msword',
271  'rtf' => 'application/rtf',
272  'xls' => 'application/vnd.ms-excel',
273  'ppt' => 'application/vnd.ms-powerpoint',
274 
275  // open office
276  'odt' => 'application/vnd.oasis.opendocument.text',
277  'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
278  );
279 
280  $ext = strtolower(array_pop(explode('.',$filename)));
281 
282  if (array_key_exists($ext, $mime_types))
283  {
284  return $mime_types[$ext];
285  }
286  elseif (function_exists('finfo_open'))
287  {
288  $finfo = finfo_open(FILEINFO_MIME);
289  $mimetype = finfo_file($finfo, $filename);
290  finfo_close($finfo);
291  return $mimetype;
292  }
293  else
294  {
295  // Prevent other file types (such as source code or configuration files) from being served
296  die("");
297  }
298  }

The documentation for this class was generated from the following file: