/**
* Table Definition for Images
*/
-require_once 'DB/DataObject.php';
+class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
class Pman_Core_DataObjects_Images extends DB_DataObject
{
{
// copy the file into the storage area..
if (!file_exists($file) || !filesize($file)) {
+ $this->err = "File $file did not exist or is 0 size";
return false;
}
}
}
+ if($this->mimetype == 'application/pdf'){
+
+ require_once 'System.php';
+
+ $this->no_of_pages = 0;
+
+ $pdfinfo = System::which('pdfinfo');
+
+ if (!empty($pdfinfo)) {
+
+ $cmd = "{$pdfinfo} {$file}";
+
+ $ret = `$cmd`;
+
+ $info = explode("\n", $ret);
+
+ foreach ($info as $i){
+
+ if(preg_match('/^Pages:[\s]*([0-9]+)/', $i, $matches)){
+ $this->no_of_pages = (empty($matches[1])) ? 0 : $matches[1];
+ continue;
+ }
+
+ }
+ }
+
+ }
+
$this->filesize = filesize($file);
$this->created = date('Y-m-d H:i:s');
return false;
}
if ($tbl->$fld) {
+ HTML_FlexyFramework::get()->page->jerr("updating images is disabled");
+ exit;
$image = DB_DataObject::factory('Images');
$image->get($tbl->$fld);
$image->beforeDelete();
empty($_FILES['imageUpload']['name']) ||
empty($_FILES['imageUpload']['type'])
) {
- $this->err = "Missing file details";
+
+ $emap = array(
+ 0=>"There is no error, the file uploaded with success",
+ 1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini",
+ 2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form" ,
+ 3=>"The uploaded file was only partially uploaded",
+ 4=>"No file was uploaded",
+ 6=>"Missing a temporary folder"
+ );
+ $estr = (empty($_FILES['imageUpload']['error']) ? '?': $emap[$_FILES['imageUpload']['error']]);
+ $this->err = "Missing file details : Error=". $estr;
return false;
}
if ($this->id) {
+ HTML_FlexyFramework::get()->page->jerr("updating images is disabled");
+ exit;
$this->beforeDelete();
}
if ( empty($this->ontable)) {
$img->find();
while ($img->fetch()) {
+ HTML_FlexyFramework::get()->page->jerr("updating images is disabled");
+ exit;
$img->beforeDelete();
$img->delete();
}
if (!$this->createFrom($_FILES['imageUpload']['tmp_name'])) {
+ $this->err = isset($this->err) ? $this->err : "createFrom Image failed";
return false;
}
return true;
}
- function toRooArray($req = array()) {
- // echo '<PRE>';print_r($req);exit;
+ function toRooArray($req) {
+
$ret= $this->toArray();
static $ff = false;
// print_r(!$this->onUpload($this));
if ( !$this->onUpload($this)) {
- $roo->jerr("File upload failed : ". (!empty($this->err) ? $this->err : ''));
+ $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()
{
}
if ($this->id) {
+ HTML_FlexyFramework::get()->page->jerr("updating images is disabled");
+ exit;
$this->beforeDelete();
}
$img->find();
while ($img->fetch()) {
+ HTML_FlexyFramework::get()->page->jerr("updating images is disabled");
+ exit;
$img->beforeDelete();
$img->delete();
}
}
+ function toBase64()
+ {
+ if(!preg_match('/^image\//', $this->mimetype)){
+ return false;
+ }
+
+ $file = $this->getStoreName();
+
+ if(!file_exists($file)){
+ return false;
+ }
+
+ $data = file_get_contents($file);
+
+ $base64 = 'data:' . $this->mimetype . ';base64,' . base64_encode($data);
+
+ return $base64;
+ }
+
}