Uploader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A noAdminSizeCheck() 0 4 1
A checkMaxFileSize() 0 11 3
1
<?php namespace XoopsModules\Smartobject;
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright    XOOPS Project https://xoops.org/
15
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 * @package
17
 * @since
18
 * @author     XOOPS Development Team
19
 */
20
21
use XoopsModules\Smartobject;
22
23
/**
24
 * !
25
 * Example
26
 *
27
 * require_once __DIR__ . '/uploader.php';
28
 * $allowed_mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png');
29
 * $maxfilesize = 50000;
30
 * $maxfilewidth = 120;
31
 * $maxfileheight = 120;
32
 * $uploader = new SmartUploader('/home/xoops/uploads', $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);
33
 * if ($uploader->fetchMedia($_POST['uploade_file_name'])) {
34
 * if (!$uploader->upload()) {
35
 * echo $uploader->getErrors();
36
 * } else {
37
 * echo '<h4>File uploaded successfully!</h4>'
38
 * echo 'Saved as: ' . $uploader->getSavedFileName() . '<br>';
39
 * echo 'Full path: ' . $uploader->getSavedDestination();
40
 * }
41
 * } else {
42
 * echo $uploader->getErrors();
43
 * }
44
 */
45
46
/**
47
 * Upload Media files
48
 *
49
 * Example of usage:
50
 * <code>
51
 * require_once __DIR__ . '/uploader.php';
52
 * $allowed_mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png');
53
 * $maxfilesize = 50000;
54
 * $maxfilewidth = 120;
55
 * $maxfileheight = 120;
56
 * $uploader = new SmartUploader('/home/xoops/uploads', $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);
57
 * if ($uploader->fetchMedia($_POST['uploade_file_name'])) {
58
 *            if (!$uploader->upload()) {
59
 *               echo $uploader->getErrors();
60
 *            } else {
61
 *               echo '<h4>File uploaded successfully!</h4>'
62
 *               echo 'Saved as: ' . $uploader->getSavedFileName() . '<br>';
63
 *               echo 'Full path: ' . $uploader->getSavedDestination();
64
 *            }
65
 * } else {
66
 *            echo $uploader->getErrors();
67
 * }
68
 * </code>
69
 *
70
 * @license GNU
71
 * @author  Kazumi Ono <[email protected]>
72
 * @link    http://smartfactory.ca The SmartFactory
73
 * @package SmartObject
74
 */
75
mt_srand((double)microtime() * 1000000);
76
77
require_once XOOPS_ROOT_PATH . '/class/uploader.php';
78
79
/**
80
 * Class SmartUploader
81
 */
82
class Uploader extends \XoopsMediaUploader
83
{
84
    public $ext;
85
    public $dimension;
86
87
    /**
88
     * No admin check for uploads
89
     */
90
    public $noAdminSizeCheck;
91
92
    /**
93
     * Constructor
94
     *
95
     * @param string    $uploadDir
96
     * @param array|int $allowedMimeTypes
97
     * @param int       $maxFileSize
98
     * @param int       $maxWidth
99
     * @param int       $maxHeight
100
     * @internal param int $cmodvalue
101
     */
102
    public function __construct($uploadDir, $allowedMimeTypes = 0, $maxFileSize, $maxWidth = 0, $maxHeight = 0)
103
    {
104
        parent::__construct($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight);
105
    }
106
107
    /**
108
     * @param $value
109
     */
110
    public function noAdminSizeCheck($value)
111
    {
112
        $this->noAdminSizeCheck = $value;
113
    }
114
115
    /**
116
     * Is the file the right size?
117
     *
118
     * @return bool
119
     */
120
    public function checkMaxFileSize()
121
    {
122
        if ($this->noAdminSizeCheck) {
123
            return true;
124
        }
125
        if ($this->mediaSize > $this->maxFileSize) {
126
            return false;
127
        }
128
129
        return true;
130
    }
131
}
132