11 include_once XOOPS_ROOT_PATH.
'/class/uploader.php';
 
   23     public function __construct($uploadDir, $maxFileSize, $allowed_exts = array()){
 
   26         $this->extensionToMime = include 
$GLOBALS[
'xoops']->path(
'include/mimetypes.inc.php');
 
   28         $this->extensionToMime =
$ev->run_event(
'rmcommon.get.mime.types', $this->extensionToMime);
 
   29         if (!is_array($this->extensionToMime)) {
 
   30             $this->extensionToMime = array();
 
   33         if (is_array($allowed_exts)) {
 
   34             foreach($allowed_exts as $ext){
 
   36                 $this->allowedMimeTypes[] = $this->extensionToMime[$ext];
 
   41         $this->uploadDir = $uploadDir;
 
   42         $this->maxFileSize = intval($maxFileSize);
 
   43         if (isset($maxWidth)) {
 
   44             $this->maxWidth = intval($maxWidth);
 
   46         if (isset($maxHeight)) {
 
   47             $this->maxHeight = intval($maxHeight);
 
   50         if (!@include_once 
$GLOBALS[
'xoops']->path(
'language/' . 
$GLOBALS[
'xoopsConfig'][
'language'] . 
'/uploader.php')) {
 
   51             include_once 
$GLOBALS[
'xoops']->path(
'language/english/uploader.php');
 
   59         if (!preg_match(
"/\.([a-zA-Z0-9]+)$/", $this->mediaName, $matched)) {
 
   60             $this->setErrors(_ER_UP_INVALIDFILENAME);
 
   63         if (isset($this->targetFileName)) {
 
   64             $this->savedFileName = $this->targetFileName;
 
   65         } 
else if (isset($this->prefix)) {
 
   66             $this->savedFileName = uniqid($this->prefix) . 
'.' . strtolower($matched[1]);
 
   68             $this->savedFileName = strtolower($this->mediaName);
 
   71         $fdata = pathinfo($this->savedFileName);
 
   72         $this->savedFileName = 
TextCleaner::sweetstring($fdata[
'filename']).($fdata[
'extension']!=
'' ? 
'.'.$fdata[
'extension'] : 
'');
 
   73         $fdata = pathinfo($this->savedFileName);
 
   75         if (file_exists($this->uploadDir . 
'/' . $this->savedFileName)){
 
   77             while(file_exists($this->uploadDir . 
'/' . $this->savedFileName)){
 
   78                 $this->savedFileName = $fdata[
'filename'].
'-'.$num.($fdata[
'extension']!=
'' ? 
'.'.$fdata[
'extension'] : 
'');
 
   83         $this->savedDestination = $this->uploadDir . 
'/' . $this->savedFileName;
 
   84         if (!move_uploaded_file($this->mediaTmpName, $this->savedDestination)) {
 
   85             $this->setErrors(sprintf(_ER_UP_FAILEDSAVEFILE, $this->savedDestination));
 
   89         $ext = strtolower(substr(strrchr($this->savedDestination, 
'.'), 1));
 
   90         if (in_array($ext, $this->imageExtensions)) {
 
   91             $info = @getimagesize($this->savedDestination);
 
   92             if ($info === 
false || $this->imageExtensions[(
int) $info[2]] != $ext) {
 
   93                 $this->setErrors(_ER_UP_SUSPICIOUSREFUSED);
 
   94                 @unlink($this->savedDestination);
 
   98         @chmod($this->savedDestination, $chmod);
 
  104         print_r($this->extensionToMime); die();