}
}
- $this->getNumberOfPages();
+ if($this->mimetype == 'application/pdf'){
+ $this->no_of_pages = $this->getPdfPages($file);
+ }
$this->filesize = filesize($file);
$this->created = date('Y-m-d H:i:s');
{
$opts = HTML_FlexyFramework::get()->Pman;
$fn = preg_replace('/[^a-z0-9\.]+/i', '_', $this->filename);
+ print_r(implode( '/', array(
+ $opts['storedir'], '_images_', date('Y/m', strtotime($this->created)), $this->id . '-'. $fn
+ )));exit;
return implode( '/', array(
$opts['storedir'], '_images_', date('Y/m', strtotime($this->created)), $this->id . '-'. $fn
));
$this->filesize = filesize($f);
+ if($this->mimetype == 'application/pdf'){
+ $this->no_of_pages = $this->getPdfPages($f);
+ }
+
$this->update($o);
return true;
return $base64;
}
- function getNumberOfPages()
+ function getPdfPages($file)
{
- $ret = false;
-
require_once 'System.php';
- $file = $this->getStoreName();
-
- if(!file_exists($file)){
- return false;
+ $page = 0;
+
+ $pdfinfo = System::which('pdfinfo');
+
+ if (!file_exists($file) || empty($pdfinfo)) {
+ return $page;
}
-
- switch ($this->mimetype) {
-
- case 'application/pdf' :
-
- $pdftk = System::which('pdftk');
-
- if (empty($pdftk)) {
- return false;
- }
-
- $cmd = "{$pdftk} {$file} dump_data";
-
- $info = `$cmd`;
-
- $infos = explode("\n", $info);
+
+ $cmd = "{$pdfinfo} {$file}";
- foreach ($infos as $i){
-
- if(!preg_match('/^NumberOfPages: ([0-9]+)/', $i, $matches)){
- continue;
- }
-
- $ret = (empty($matches[1])) ? false : $matches[1];
- break;
- }
-
- break;
- default :
- break;
+ $ret = `$cmd`;
+
+ $info = explode("\n", $ret);
+
+ foreach ($info as $i){
+
+ if(!preg_match('/^Pages:[\s]*([0-9]+)/', $i, $matches)){
+ continue;
+ }
+
+ $page = (empty($matches[1])) ? 0 : $matches[1];
}
- return $ret;
+ return $page;
}
}