}
}
- $this->getNumberOfPages($file);
+ 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 $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' :
-
- $pdftk = System::which('pdftk');
-
- if (empty($pdftk)) {
- return false;
- }
-
- $cmd = "{$pdftk} {$file} dump_data";
-
- $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;
- }
-
}