Passed
Push — master ( 7cb178...ac4679 )
by Fabio
04:35
created

TActiveFileUploadItem::saveAs()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
nc 3
nop 2
dl 0
loc 10
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * TActiveFileUploadItem class file
4
 *
5
 * @author LANDWEHR Computer und Software GmbH <[email protected]>
6
 * @link https://github.com/pradosoft/prado4
7
 * @license https://github.com/pradosoft/prado4/blob/master/LICENSE
8
 * @package Prado\Web\UI\WebControls
9
 */
10
11
namespace Prado\Web\UI\ActiveControls;
12
13
/**
14
 * TActiveFileUploadItem class
15
 *
16
 * TActiveFileUploadItem represents a single uploaded file from {@link TActiveFileUpload} and
17
 * is especially needed when {@link TFileUpload::setMultiple} is set to true.
18
 *
19
 * See {@link TFileUpload} documentation for more details.
20
 *
21
 * @author LANDWEHR Computer und Software GmbH <[email protected]>
22
 * @package Prado\Web\UI\ActiveControls
23
 * @since 4.0
24
 */
25
class TActiveFileUploadItem extends \Prado\Web\UI\WebControls\TFileUploadItem
26
{
27
	/**
28
	 * Saves the uploaded file.
29
	 * @param string $fileName the file name used to save the uploaded file
30
	 * @param bool $deleteTempFile whether to delete the temporary file after saving.
31
	 * If true, you will not be able to save the uploaded file again.
32
	 * @return bool true if the file saving is successful
33
	 */
34
	public function saveAs($fileName, $deleteTempFile = true)
35
	{
36
		if (($this->_errorCode === UPLOAD_ERR_OK) && (file_exists($this->_localName))) {
37
			if ($deleteTempFile) {
38
				return rename($this->_localName, $fileName);
39
			} else {
40
				return copy($this->_localName, $fileName);
41
			}
42
		} else {
43
			return false;
44
		}
45
	}
46
}
47