Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update filestore/lib/Model/File.php

added some error checking for finfo in filestore add-on
  • Loading branch information...
commit 5a69383599be84e386f08494208e1a287d762c4c 1 parent 3ee5f64
@DarkSide666 DarkSide666 authored
Showing with 15 additions and 11 deletions.
  1. +15 −11 filestore/lib/Model/File.php
View
26 filestore/lib/Model/File.php
@@ -1,13 +1,14 @@
<?php
namespace filestore;
class Model_File extends \Model_Table {
- public $table='filestore_file';
+ public $table='filestore_file';
- public $entity_filestore_type='Type';
- public $entity_filestore_volume='Volume';
+ public $entity_filestore_type='Type';
+ public $entity_filestore_volume='Volume';
+ public $magic_file=null; // path to magic database file used in finfo-open(), null = default
public $import_mode=null;
- public $import_source=null;
+ public $import_source=null;
function init(){
parent::init();
@@ -83,13 +84,16 @@ function getAvailableVolumeID(){
return $id;
}
- function getFiletypeID($mime_type = null, $add = false){
+ function getFiletypeID($mime_type = null, $add = false){
if($mime_type == null){
$path = $this->get('filename')?$this->getPath():$this->import_source;
if(!$path)throw $this->exception('Load file entry from filestore or import');
-
- $finfo = finfo_open(FILEINFO_MIME_TYPE);
- $mime_type= finfo_file($finfo, $path);
+
+ if(!function_exists('finfo_open'))throw $this->exception('You have to enable php_fileinfo extension of PHP.');
+ $finfo = finfo_open(FILEINFO_MIME_TYPE, $this->magic_file);
+ if($finfo===false)throw $this->exception("Can't find magic_file in finfo_open().")
+ ->addMoreInfo('Magic_file: ',isnull($this->magic_file)?'default':$this->magic_file);
+ $mime_type = finfo_file($finfo, $path);
finfo_close($finfo);
}
$c=$this->add('filestore/Model_'.$this->entity_filestore_type);
@@ -102,9 +106,9 @@ function getFiletypeID($mime_type = null, $add = false){
throw $this->exception('This file type is not allowed for upload')
->addMoreInfo('type',$mime_type);
}
- }
- return $data['id'];
- }
+ }
+ return $data['id'];
+ }
function generateFilename(){
$this->hook("beforeGenerateFilename");
if ($filename = $this->get("filename")){
Please sign in to comment.
Something went wrong with that request. Please try again.