Overview

Namespaces

  • Jlab
    • Eloglib

Classes

  • Jlab\Eloglib\Attachment
  • Jlab\Eloglib\FileAttachment
  • Jlab\Eloglib\Logentry
  • Jlab\Eloglib\LogentryUtil
  • Jlab\Eloglib\URLAttachment
  • Jlab\Eloglib\User

Exceptions

  • Jlab\Eloglib\InvalidXMLException
  • Jlab\Eloglib\IOException
  • Jlab\Eloglib\LogentryException
  • Jlab\Eloglib\LogRuntimeException
  • Jlab\Eloglib\ServerException
  • Jlab\Eloglib\UserException
  • Overview
  • Namespace
  • Class
 1: <?php
 2: /**
 3:  * Created by PhpStorm.
 4:  * User: theo
 5:  * Date: 9/6/17
 6:  * Time: 10:51 AM
 7:  */
 8: 
 9: namespace Jlab\Eloglib;
10: 
11: 
12: class FileAttachment extends Attachment
13: {
14: 
15: 
16:     /**
17:      *
18:      * @param string $filename full path to file
19:      * @param string $caption text description of attachment
20:      * @param string $type explicitly specify mime-type
21:      *
22:      */
23:     function __construct($filename, $caption = '', $type = '')
24:     {
25:         $this->encoding = 'base64';
26:         $this->readFromFile($filename);
27:         $this->setMimeType($filename, $type);
28:         $this->caption = $caption;
29:     }
30: 
31:     /**
32:      * Reads contents of a file to $this->data and stores
33:      * the base filename in $this->filename.
34:      *
35:      * @param $filename
36:      * @throws IOException
37:      */
38:     protected function readFromFile($filename){
39:         $data = file_get_contents($filename);
40:         if ($data === false) {
41:             throw new IOException("Unable to read contents of attachment file");
42:         }
43:         $this->data = base64_encode($data);
44:         $this->filename =  basename($filename);
45:     }
46: 
47:     /**
48:      * Sets the mime type.
49:      * @param string $filename full path to file
50:      * @param mixed $type string type-name or null for auto-detect
51:      */
52:     protected function setMimeType($filename, $type)
53:     {
54:         if ($type) {
55:             $this->type = $type;
56:         } else {
57:             // Try to get the mime type
58:             $finfo = finfo_open(FILEINFO_MIME_TYPE);
59:             $this->type = finfo_file($finfo, $filename);
60:         }
61:     }
62: 
63: } //class
API documentation generated by ApiGen