Completed
Push — master ( d09fc3...fde49e )
by samayo
05:21
created
src/bulletproof.php 1 patch
Indentation   +417 added lines, -417 removed lines patch added patch discarded remove patch
@@ -16,426 +16,426 @@
 block discarded – undo
16 16
 
17 17
 class Image implements \ArrayAccess
18 18
 {
19
-    /**
20
-     * @var string The new image name, to be provided or will be generated.
21
-     */
22
-    protected $name;
23
-
24
-    /**
25
-     * @var int The image width in pixels
26
-     */
27
-    protected $width;
28
-
29
-    /**
30
-     * @var int The image height in pixels
31
-     */
32
-    protected $height;
33
-
34
-    /**
35
-     * @var string The image mime type (extension)
36
-     */
37
-    protected $mime;
38
-
39
-    /**
40
-     * @var string The full image path (dir + image + mime)
41
-     */
42
-    protected $fullPath;
43
-
44
-    /**
45
-     * @var string The folder or image storage location
46
-     */
47
-    protected $location;
48
-
49
-    /**
50
-     * @var array A json format of all information about an image
51
-     */
52
-    protected $serialize = array();
53
-
54
-    /**
55
-     * @var array The min and max image size allowed for upload (in bytes)
56
-     */
57
-    protected $size = array(100, 50000);
58
-
59
-    /**
60
-     * @var array The max height and width image allowed
61
-     */
62
-    protected $dimensions = array(500, 5000);
63
-
64
-    /**
65
-     * @var array The mime types allowed for upload
66
-     */
67
-    protected $mimeTypes = array("jpeg", "png", "gif");
68
-
69
-    /**
70
-     * @var array list of known image types
71
-     */
72
-    protected $imageMimes = array(
73
-        1 => "gif", "jpeg", "png", "swf", "psd",
74
-        "bmp", "tiff", "tiff", "jpc", "jp2", "jpx",
75
-        "jb2", "swc", "iff", "wbmp", "xbm", "ico"
76
-    );
77
-
78
-    /**
79
-     * @var array storage for the $_FILES global array
80
-     */
81
-    private $_files = array();
82
-
83
-    /**
84
-     * @var string storage for any errors
85
-     */
86
-    private $error = "";
87
-
88
-    /**
89
-     * @param array $_files represents the $_FILES array passed as dependancy
90
-     */
91
-    public function __construct(array $_files = [])
92
-    {
93
-        $this->_files = $_files;
94
-    }
95
-
96
-    /**
97
-     * Gets the real image mime type
98
-     *
99
-     * @param $tmp_name string The upload tmp directory
100
-     *
101
-     * @return bool|string
102
-     */
103
-    protected function getImageMime($tmp_name)
104
-    {
105
-        if (isset($this->imageMimes[exif_imagetype($tmp_name)])) {
106
-            return $this->imageMimes [exif_imagetype($tmp_name)];
107
-        }
108
-        return false;
109
-    }
110
-
111
-    /**
112
-     * array offset \ArrayAccess
113
-     * unused
114
-     */
115
-    public function offsetSet($offset, $value){}
116
-    public function offsetExists($offset){}
117
-    public function offsetUnset($offset){}
118
-
119
-    /**
120
-     * Gets array value \ArrayAccess
121
-     *
122
-     * @param mixed $offset
123
-     *
124
-     * @return bool|mixed
125
-     */
126
-    public function offsetGet($offset)
127
-    {
128
-        if ($offset == "error") {
129
-            return $this->error;
130
-        }
131
-
132
-        if (isset($this->_files[$offset]) && file_exists($this->_files[$offset]["tmp_name"])) {
133
-            $this->_files = $this->_files[$offset];
134
-            return true;
135
-        }
19
+	/**
20
+	 * @var string The new image name, to be provided or will be generated.
21
+	 */
22
+	protected $name;
23
+
24
+	/**
25
+	 * @var int The image width in pixels
26
+	 */
27
+	protected $width;
28
+
29
+	/**
30
+	 * @var int The image height in pixels
31
+	 */
32
+	protected $height;
33
+
34
+	/**
35
+	 * @var string The image mime type (extension)
36
+	 */
37
+	protected $mime;
38
+
39
+	/**
40
+	 * @var string The full image path (dir + image + mime)
41
+	 */
42
+	protected $fullPath;
43
+
44
+	/**
45
+	 * @var string The folder or image storage location
46
+	 */
47
+	protected $location;
48
+
49
+	/**
50
+	 * @var array A json format of all information about an image
51
+	 */
52
+	protected $serialize = array();
53
+
54
+	/**
55
+	 * @var array The min and max image size allowed for upload (in bytes)
56
+	 */
57
+	protected $size = array(100, 50000);
58
+
59
+	/**
60
+	 * @var array The max height and width image allowed
61
+	 */
62
+	protected $dimensions = array(500, 5000);
63
+
64
+	/**
65
+	 * @var array The mime types allowed for upload
66
+	 */
67
+	protected $mimeTypes = array("jpeg", "png", "gif");
68
+
69
+	/**
70
+	 * @var array list of known image types
71
+	 */
72
+	protected $imageMimes = array(
73
+		1 => "gif", "jpeg", "png", "swf", "psd",
74
+		"bmp", "tiff", "tiff", "jpc", "jp2", "jpx",
75
+		"jb2", "swc", "iff", "wbmp", "xbm", "ico"
76
+	);
77
+
78
+	/**
79
+	 * @var array storage for the $_FILES global array
80
+	 */
81
+	private $_files = array();
82
+
83
+	/**
84
+	 * @var string storage for any errors
85
+	 */
86
+	private $error = "";
87
+
88
+	/**
89
+	 * @param array $_files represents the $_FILES array passed as dependancy
90
+	 */
91
+	public function __construct(array $_files = [])
92
+	{
93
+		$this->_files = $_files;
94
+	}
95
+
96
+	/**
97
+	 * Gets the real image mime type
98
+	 *
99
+	 * @param $tmp_name string The upload tmp directory
100
+	 *
101
+	 * @return bool|string
102
+	 */
103
+	protected function getImageMime($tmp_name)
104
+	{
105
+		if (isset($this->imageMimes[exif_imagetype($tmp_name)])) {
106
+			return $this->imageMimes [exif_imagetype($tmp_name)];
107
+		}
108
+		return false;
109
+	}
110
+
111
+	/**
112
+	 * array offset \ArrayAccess
113
+	 * unused
114
+	 */
115
+	public function offsetSet($offset, $value){}
116
+	public function offsetExists($offset){}
117
+	public function offsetUnset($offset){}
118
+
119
+	/**
120
+	 * Gets array value \ArrayAccess
121
+	 *
122
+	 * @param mixed $offset
123
+	 *
124
+	 * @return bool|mixed
125
+	 */
126
+	public function offsetGet($offset)
127
+	{
128
+		if ($offset == "error") {
129
+			return $this->error;
130
+		}
131
+
132
+		if (isset($this->_files[$offset]) && file_exists($this->_files[$offset]["tmp_name"])) {
133
+			$this->_files = $this->_files[$offset];
134
+			return true;
135
+		}
136 136
         
137
-        return false;
138
-    }
139
-
140
-    /**
141
-     * Renames image
142
-     *
143
-     * @param null $isNameGiven if null, image will be auto-generated
144
-     *
145
-     * @return $this
146
-     */
147
-    public function setName($isNameProvided = null)
148
-    {
149
-        if ($isNameProvided) {
150
-            $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING);
151
-        }
137
+		return false;
138
+	}
139
+
140
+	/**
141
+	 * Renames image
142
+	 *
143
+	 * @param null $isNameGiven if null, image will be auto-generated
144
+	 *
145
+	 * @return $this
146
+	 */
147
+	public function setName($isNameProvided = null)
148
+	{
149
+		if ($isNameProvided) {
150
+			$this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING);
151
+		}
152 152
         
153
-        return $this;
154
-    }
155
-
156
-    /**
157
-     * Define a mime type for uploading
158
-     *
159
-     * @param array $fileTypes
160
-     *
161
-     * @return $this
162
-     */
163
-    public function setMime(array $fileTypes)
164
-    {
165
-        $this->mimeTypes = $fileTypes;
166
-        return $this;
167
-    }
168
-
169
-    /**
170
-     * Define a min and max image size for uploading
171
-     *
172
-     * @param $min int minimum value in bytes
173
-     * @param $max int maximum value in bytes
174
-     *
175
-     * @return $this
176
-     */
177
-    public function setSize($min, $max)
178
-    {
179
-        $this->size = array($min, $max);
180
-        return $this;
181
-    }
182
-
183
-    /**
184
-     * Creates a location for upload storage
185
-     *
186
-     * @param $dir string the folder name to create
187
-     * @param int $permission chmod permission
188
-     *
189
-     * @return $this
190
-     */
191
-    public function setLocation($dir = "bulletproof", $permission = 0666)
192
-    {
193
-        if (!file_exists($dir) && !is_dir($dir) && !$this->location) {
194
-            $createFolder = @mkdir("" . $dir, (int) $permission, true);
195
-            if (!$createFolder) {
196
-                $this->error = "Folder " . $dir . " could not be created";
197
-                return;
198
-            }
199
-        }
200
-
201
-        $this->location = $dir;
202
-        return $this;
203
-    }
204
-
205
-    /**
206
-     * Sets acceptable max image height and width
207
-     *
208
-     * @param $maxWidth int max width value
209
-     * @param $maxHeight int max height value
210
-     *
211
-     * @return $this
212
-     */
213
-    public function setDimension($maxWidth, $maxHeight)
214
-    {
215
-        $this->dimensions = array($maxWidth, $maxHeight);
216
-        return $this;
217
-    }
218
-
219
-    /**
220
-     * Returns the image name
221
-     *
222
-     * @return string
223
-     */
224
-    public function getName()
225
-    {
226
-        if (!$this->name) {
227
-           return  uniqid(true) . "_" . str_shuffle(implode(range("e", "q")));
228
-        }
229
-
230
-        return $this->name;
231
-    }
232
-
233
-    /**
234
-     * Returns the full path of the image ex "location/image.mime"
235
-     *
236
-     * @return string
237
-     */
238
-    public function getFullPath()
239
-    {
240
-        $this->fullPath = $this->location . "/" . $this->name . "." . $this->mime;
241
-        return $this->fullPath;
242
-    }
243
-
244
-    /**
245
-     * Returns the image size in bytes
246
-     *
247
-     * @return int
248
-     */
249
-    public function getSize()
250
-    {
251
-        return (int) $this->_files["size"];
252
-    }
253
-
254
-    /**
255
-     * Returns the image height in pixels
256
-     *
257
-     * @return int
258
-     */
259
-    public function getHeight()
260
-    {
261
-        if ($this->height != null) {
262
-            return $this->height;
263
-        }
264
-
265
-        list(, $height) = getImageSize($this->_files["tmp_name"]); 
266
-        return $height;
267
-    }
268
-
269
-    /**
270
-     * Returns the image width
271
-     *
272
-     * @return int
273
-     */
274
-    public function getWidth()
275
-    {
276
-        if ($this->width != null) {
277
-            return $this->width;
278
-        }
279
-
280
-        list($width) = getImageSize($this->_files["tmp_name"]); 
281
-        return $width;
282
-    }
283
-
284
-    /**
285
-     * Returns the storage / folder name
286
-     *
287
-     * @return string
288
-     */
289
-    public function getLocation()
290
-    {
291
-        if(!$this->location){
292
-            $this->setLocation(); 
293
-        }
294
-
295
-        return $this->location; 
296
-    }
297
-
298
-    /**
299
-     * Returns a JSON format of the image width, height, name, mime ...
300
-     *
301
-     * @return string
302
-     */
303
-    public function getJson()
304
-    {
305
-        return json_encode($this->serialize);
306
-    }
307
-
308
-    /**
309
-     * Returns the image mime type
310
-     *
311
-     * @return string
312
-     */
313
-    public function getMime()
314
-    {
315
-        return $this->mime;
316
-    }
317
-
318
-    /**
319
-     * Returns error string or false if no errors occurred
320
-     *
321
-     * @return string|bool
322
-     */
323
-    public function getError(){
324
-        return $this->error != "" ? $this->error : false;
325
-    }
326
-
327
-    /**
328
-     * Checks for the common upload errors
329
-     *
330
-     * @param $e int error constant
331
-     */
332
-    protected function uploadErrors($e)
333
-    {
334
-        $errors = array(
335
-            UPLOAD_ERR_OK           => "",
336
-            UPLOAD_ERR_INI_SIZE     => "Image is larger than the specified amount set by the server",
337
-            UPLOAD_ERR_FORM_SIZE    => "Image is larger than the specified amount specified by browser",
338
-            UPLOAD_ERR_PARTIAL      => "Image could not be fully uploaded. Please try again later",
339
-            UPLOAD_ERR_NO_FILE      => "Image is not found",
340
-            UPLOAD_ERR_NO_TMP_DIR   => "Can't write to disk, due to server configuration ( No tmp dir found )",
341
-            UPLOAD_ERR_CANT_WRITE   => "Failed to write file to disk. Please check you file permissions",
342
-            UPLOAD_ERR_EXTENSION    => "A PHP extension has halted this file upload process"
343
-        );
344
-        return $errors[$e];
345
-    }
346
-
347
-    /**
348
-     * Main upload method.
349
-     * This is where all the monkey business happens
350
-     *
351
-     * @return $this|bool
352
-     */
353
-    public function upload()
354
-    {
355
-        /* modify variable names for convenience */
356
-        $image = $this; 
357
-        $files = $this->_files;
358
-
359
-        /* initialize image properties */
360
-        $image->name     = $image->getName();
361
-        $image->width    = $image->getWidth();
362
-        $image->height   = $image->getHeight(); 
363
-        $image->location = $image->getLocation();
364
-
365
-        /* get image sizes */
366
-        list($minSize, $maxSize) = $image->size;
367
-
368
-        /* check for common upload errors */
369
-        if($image->error = $image->uploadErrors($files["error"])){
370
-            return ;
371
-        }
372
-
373
-        /* check image for valid mime types and return mime */
374
-        $image->mime = $image->getImageMime($files["tmp_name"]);
375
-
376
-        /* validate image mime type */
377
-        if (!in_array($image->mime, $image->mimeTypes)) {
378
-            $ext = implode(", ", $image->mimeTypes);
379
-            $image->error = "Invalid File! Only ($ext) image types are allowed";
380
-            return ;
381
-        }     
382
-
383
-        /* check image size based on the settings */
384
-        if ($files["size"] < $minSize || $files["size"] > $maxSize) {
385
-            $min = intval($minSize / 1000) ?: 1; $max = intval($maxSize / 1000);
153
+		return $this;
154
+	}
155
+
156
+	/**
157
+	 * Define a mime type for uploading
158
+	 *
159
+	 * @param array $fileTypes
160
+	 *
161
+	 * @return $this
162
+	 */
163
+	public function setMime(array $fileTypes)
164
+	{
165
+		$this->mimeTypes = $fileTypes;
166
+		return $this;
167
+	}
168
+
169
+	/**
170
+	 * Define a min and max image size for uploading
171
+	 *
172
+	 * @param $min int minimum value in bytes
173
+	 * @param $max int maximum value in bytes
174
+	 *
175
+	 * @return $this
176
+	 */
177
+	public function setSize($min, $max)
178
+	{
179
+		$this->size = array($min, $max);
180
+		return $this;
181
+	}
182
+
183
+	/**
184
+	 * Creates a location for upload storage
185
+	 *
186
+	 * @param $dir string the folder name to create
187
+	 * @param int $permission chmod permission
188
+	 *
189
+	 * @return $this
190
+	 */
191
+	public function setLocation($dir = "bulletproof", $permission = 0666)
192
+	{
193
+		if (!file_exists($dir) && !is_dir($dir) && !$this->location) {
194
+			$createFolder = @mkdir("" . $dir, (int) $permission, true);
195
+			if (!$createFolder) {
196
+				$this->error = "Folder " . $dir . " could not be created";
197
+				return;
198
+			}
199
+		}
200
+
201
+		$this->location = $dir;
202
+		return $this;
203
+	}
204
+
205
+	/**
206
+	 * Sets acceptable max image height and width
207
+	 *
208
+	 * @param $maxWidth int max width value
209
+	 * @param $maxHeight int max height value
210
+	 *
211
+	 * @return $this
212
+	 */
213
+	public function setDimension($maxWidth, $maxHeight)
214
+	{
215
+		$this->dimensions = array($maxWidth, $maxHeight);
216
+		return $this;
217
+	}
218
+
219
+	/**
220
+	 * Returns the image name
221
+	 *
222
+	 * @return string
223
+	 */
224
+	public function getName()
225
+	{
226
+		if (!$this->name) {
227
+		   return  uniqid(true) . "_" . str_shuffle(implode(range("e", "q")));
228
+		}
229
+
230
+		return $this->name;
231
+	}
232
+
233
+	/**
234
+	 * Returns the full path of the image ex "location/image.mime"
235
+	 *
236
+	 * @return string
237
+	 */
238
+	public function getFullPath()
239
+	{
240
+		$this->fullPath = $this->location . "/" . $this->name . "." . $this->mime;
241
+		return $this->fullPath;
242
+	}
243
+
244
+	/**
245
+	 * Returns the image size in bytes
246
+	 *
247
+	 * @return int
248
+	 */
249
+	public function getSize()
250
+	{
251
+		return (int) $this->_files["size"];
252
+	}
253
+
254
+	/**
255
+	 * Returns the image height in pixels
256
+	 *
257
+	 * @return int
258
+	 */
259
+	public function getHeight()
260
+	{
261
+		if ($this->height != null) {
262
+			return $this->height;
263
+		}
264
+
265
+		list(, $height) = getImageSize($this->_files["tmp_name"]); 
266
+		return $height;
267
+	}
268
+
269
+	/**
270
+	 * Returns the image width
271
+	 *
272
+	 * @return int
273
+	 */
274
+	public function getWidth()
275
+	{
276
+		if ($this->width != null) {
277
+			return $this->width;
278
+		}
279
+
280
+		list($width) = getImageSize($this->_files["tmp_name"]); 
281
+		return $width;
282
+	}
283
+
284
+	/**
285
+	 * Returns the storage / folder name
286
+	 *
287
+	 * @return string
288
+	 */
289
+	public function getLocation()
290
+	{
291
+		if(!$this->location){
292
+			$this->setLocation(); 
293
+		}
294
+
295
+		return $this->location; 
296
+	}
297
+
298
+	/**
299
+	 * Returns a JSON format of the image width, height, name, mime ...
300
+	 *
301
+	 * @return string
302
+	 */
303
+	public function getJson()
304
+	{
305
+		return json_encode($this->serialize);
306
+	}
307
+
308
+	/**
309
+	 * Returns the image mime type
310
+	 *
311
+	 * @return string
312
+	 */
313
+	public function getMime()
314
+	{
315
+		return $this->mime;
316
+	}
317
+
318
+	/**
319
+	 * Returns error string or false if no errors occurred
320
+	 *
321
+	 * @return string|bool
322
+	 */
323
+	public function getError(){
324
+		return $this->error != "" ? $this->error : false;
325
+	}
326
+
327
+	/**
328
+	 * Checks for the common upload errors
329
+	 *
330
+	 * @param $e int error constant
331
+	 */
332
+	protected function uploadErrors($e)
333
+	{
334
+		$errors = array(
335
+			UPLOAD_ERR_OK           => "",
336
+			UPLOAD_ERR_INI_SIZE     => "Image is larger than the specified amount set by the server",
337
+			UPLOAD_ERR_FORM_SIZE    => "Image is larger than the specified amount specified by browser",
338
+			UPLOAD_ERR_PARTIAL      => "Image could not be fully uploaded. Please try again later",
339
+			UPLOAD_ERR_NO_FILE      => "Image is not found",
340
+			UPLOAD_ERR_NO_TMP_DIR   => "Can't write to disk, due to server configuration ( No tmp dir found )",
341
+			UPLOAD_ERR_CANT_WRITE   => "Failed to write file to disk. Please check you file permissions",
342
+			UPLOAD_ERR_EXTENSION    => "A PHP extension has halted this file upload process"
343
+		);
344
+		return $errors[$e];
345
+	}
346
+
347
+	/**
348
+	 * Main upload method.
349
+	 * This is where all the monkey business happens
350
+	 *
351
+	 * @return $this|bool
352
+	 */
353
+	public function upload()
354
+	{
355
+		/* modify variable names for convenience */
356
+		$image = $this; 
357
+		$files = $this->_files;
358
+
359
+		/* initialize image properties */
360
+		$image->name     = $image->getName();
361
+		$image->width    = $image->getWidth();
362
+		$image->height   = $image->getHeight(); 
363
+		$image->location = $image->getLocation();
364
+
365
+		/* get image sizes */
366
+		list($minSize, $maxSize) = $image->size;
367
+
368
+		/* check for common upload errors */
369
+		if($image->error = $image->uploadErrors($files["error"])){
370
+			return ;
371
+		}
372
+
373
+		/* check image for valid mime types and return mime */
374
+		$image->mime = $image->getImageMime($files["tmp_name"]);
375
+
376
+		/* validate image mime type */
377
+		if (!in_array($image->mime, $image->mimeTypes)) {
378
+			$ext = implode(", ", $image->mimeTypes);
379
+			$image->error = "Invalid File! Only ($ext) image types are allowed";
380
+			return ;
381
+		}     
382
+
383
+		/* check image size based on the settings */
384
+		if ($files["size"] < $minSize || $files["size"] > $maxSize) {
385
+			$min = intval($minSize / 1000) ?: 1; $max = intval($maxSize / 1000);
386 386
             
387
-            $image->error = "Image size should be atleast more than min: $min and less than max: $max kb";
388
-            return ;
389
-        }
390
-
391
-        /* check image dimension */
392
-        list($allowedWidth, $allowedHeight) = $image->dimensions;
393
-
394
-        if ($image->height > $allowedHeight || $image->width > $allowedWidth) {
395
-            $image->error = "Image height/width should be less than ' $allowedHeight \ $allowedWidth ' pixels";
396
-            return ;
397
-        }
398
-
399
-        if($image->height < 4 || $image->width < 4){
400
-            $image->error = "Invalid! Image height/width is too small or maybe corrupted"; 
401
-            return ;
402
-        }
387
+			$image->error = "Image size should be atleast more than min: $min and less than max: $max kb";
388
+			return ;
389
+		}
390
+
391
+		/* check image dimension */
392
+		list($allowedWidth, $allowedHeight) = $image->dimensions;
393
+
394
+		if ($image->height > $allowedHeight || $image->width > $allowedWidth) {
395
+			$image->error = "Image height/width should be less than ' $allowedHeight \ $allowedWidth ' pixels";
396
+			return ;
397
+		}
398
+
399
+		if($image->height < 4 || $image->width < 4){
400
+			$image->error = "Invalid! Image height/width is too small or maybe corrupted"; 
401
+			return ;
402
+		}
403 403
  
404
-        /* set and get folder name */
405
-        $image->fullPath = $image->location. "/" . $image->name . "." . $image->mime;
406
-
407
-        /* gather image info for json storage */ 
408
-        $image->serialize = array(
409
-            "name"     => $image->name,
410
-            "mime"     => $image->mime,
411
-            "height"   => $image->height,
412
-            "width"    => $image->width,
413
-            "size"     => $files["size"],
414
-            "location" => $image->location,
415
-            "fullpath" => $image->fullPath
416
-        );
417
-
418
-        if ($image->error === "") {
419
-            $moveUpload = $image->moveUploadedFile($files["tmp_name"], $image->fullPath);
420
-            if (false !== $moveUpload) {
421
-                return $image;
422
-            }
423
-        }
404
+		/* set and get folder name */
405
+		$image->fullPath = $image->location. "/" . $image->name . "." . $image->mime;
406
+
407
+		/* gather image info for json storage */ 
408
+		$image->serialize = array(
409
+			"name"     => $image->name,
410
+			"mime"     => $image->mime,
411
+			"height"   => $image->height,
412
+			"width"    => $image->width,
413
+			"size"     => $files["size"],
414
+			"location" => $image->location,
415
+			"fullpath" => $image->fullPath
416
+		);
417
+
418
+		if ($image->error === "") {
419
+			$moveUpload = $image->moveUploadedFile($files["tmp_name"], $image->fullPath);
420
+			if (false !== $moveUpload) {
421
+				return $image;
422
+			}
423
+		}
424 424
         
425
-        $image->error = "Upload failed, Unknown error occured";
426
-        return false;
427
-    }
428
-
429
-    /**
430
-     * Final upload method to be called, isolated for testing purposes
431
-     *
432
-     * @param $tmp_name int the temporary location of the image file
433
-     * @param $destination int upload destination
434
-     *
435
-     * @return bool
436
-     */
437
-    public function moveUploadedFile($tmp_name, $destination)
438
-    {
439
-        return move_uploaded_file($tmp_name, $destination);
440
-    }
425
+		$image->error = "Upload failed, Unknown error occured";
426
+		return false;
427
+	}
428
+
429
+	/**
430
+	 * Final upload method to be called, isolated for testing purposes
431
+	 *
432
+	 * @param $tmp_name int the temporary location of the image file
433
+	 * @param $destination int upload destination
434
+	 *
435
+	 * @return bool
436
+	 */
437
+	public function moveUploadedFile($tmp_name, $destination)
438
+	{
439
+		return move_uploaded_file($tmp_name, $destination);
440
+	}
441 441
 }
Please login to merge, or discard this patch.