-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTemporaryFile.php
More file actions
40 lines (34 loc) · 1.04 KB
/
TemporaryFile.php
File metadata and controls
40 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/**
* TemporaryFile
*
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
App::uses('File', 'Utility');
App::uses('TemporaryFolder', 'Files.Utility');
App::uses('Security', 'Utility');
/**
* Class TemporaryFile
*/
class TemporaryFile extends File {
/**
* @var TemporaryFolder テンポラリファイルを配置するテンポラリフォルダ
*/
protected $_tmpFolder;
/**
* TemporaryFile constructor.
*
* @param string $folderPath テンポラリフォルダを作成するフォルダパス。指定されなければテンポラリフォルダを作成する
*/
public function __construct($folderPath = null) {
if ($folderPath === null) {
$this->_tmpFolder = new TemporaryFolder();
$folderPath = $this->_tmpFolder->path;
}
$fileName = Security::hash(mt_rand() . microtime(), 'md5');
register_shutdown_function(array($this, 'delete'));
parent::__construct($folderPath . DS . $fileName, true);
}
}