}
}
+ $this->getNumberOfPages($file);
+
$this->filesize = filesize($file);
$this->created = date('Y-m-d H:i:s');
$roo->jerr("File upload failed : error = ". (!empty($this->err) ? $this->err : ''));
}
- $roo->addEvent("ADD", $this, $this->toEventString());
+ $this->addEvent($ar, $roo);
$r = DB_DataObject::factory($this->tableName());
$r->id = $this->id;
}
+ function addEvent($ar, $roo)
+ {
+ $roo->addEvent("ADD", $this, $this->toEventString());
+ }
+
function toEventString()
{
function toBase64()
{
+ if(!preg_match('/^image\//', $this->mimetype)){
+ return false;
+ }
+
$file = $this->getStoreName();
if(!file_exists($file)){
return false;
}
- $type = pathinfo($file, PATHINFO_EXTENSION);
- $data = file_get_contents($path);
- $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
+ $data = file_get_contents($file);
+
+ $base64 = 'data:' . $this->mimetype . ';base64,' . base64_encode($data);
+
+ return $base64;
+ }
+
+ function getNumberOfPages($file)
+ {
+ require_once 'System.php';
+
+ $this->no_of_pages = 0;
+
+ if(!file_exists($file)){
+ return;
+ }
+
+ /*
+ * We handle pdf only at present
+ */
+ switch ($this->mimetype) {
+
+ case 'application/pdf' :
+
+ $pdfinfo = System::which('pdfinfo');
+
+ if (empty($pdfinfo)) {
+ return false;
+ }
+
+ $cmd = "{$pdfinfo} {$file}";
+
+ $info = `$cmd`;
+
+ $infos = explode("\n", $info);
+
+ foreach ($infos as $i){
+
+ if(!preg_match('/^NumberOfPages: ([0-9]+)/', $i, $matches)){
+ continue;
+ }
+
+ $ret = (empty($matches[1])) ? false : $matches[1];
+ break;
+ }
+
+ break;
+ default :
+ break;
+ }
+
+ return;
}
}