|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* APWEB Framework (http://framework.artphoweb.com/) |
|
5
|
|
|
* APWEB FW(tm) : Rapid Development Framework (http://framework.artphoweb.com/) |
|
6
|
|
|
* |
|
7
|
|
|
* Licensed under The MIT License |
|
8
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
|
9
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
10
|
|
|
* |
|
11
|
|
|
* @link http://github.com/zebedeu/artphoweb for the canonical source repository |
|
12
|
|
|
* @copyright (c) 2015. APWEB Software Technologies AO Inc. (http://www.artphoweb.com) |
|
13
|
|
|
* @license http://framework.artphoweb.com/license/new-bsd New BSD License |
|
14
|
|
|
* @author Marcio Zebedeu - [email protected] |
|
15
|
|
|
* @version 1.0.0 |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class Uploads |
|
20
|
|
|
* @package Ballybran\Helpers |
|
21
|
|
|
*/ |
|
22
|
|
|
class Uploads |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var |
|
27
|
|
|
*/ |
|
28
|
|
|
public $path; |
|
29
|
|
|
/** |
|
30
|
|
|
* @var |
|
31
|
|
|
*/ |
|
32
|
|
|
private $tmp; |
|
33
|
|
|
/** |
|
34
|
|
|
* @var |
|
35
|
|
|
*/ |
|
36
|
|
|
public $name; |
|
37
|
|
|
/** |
|
38
|
|
|
* @var |
|
39
|
|
|
*/ |
|
40
|
|
|
public $size; |
|
41
|
|
|
/** |
|
42
|
|
|
* @var |
|
43
|
|
|
*/ |
|
44
|
|
|
public $type; |
|
45
|
|
|
/** |
|
46
|
|
|
* @var array |
|
47
|
|
|
*/ |
|
48
|
|
|
private $explode; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var |
|
52
|
|
|
*/ |
|
53
|
|
|
private $ext; |
|
54
|
|
|
/** |
|
55
|
|
|
* @var |
|
56
|
|
|
*/ |
|
57
|
|
|
private $dir; |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Uploads constructor. |
|
62
|
|
|
*/ |
|
63
|
|
|
function __construct() |
|
64
|
|
|
{ |
|
65
|
|
|
|
|
66
|
|
|
if (isset($_FILES['archive'])) { |
|
67
|
|
|
|
|
68
|
|
|
foreach ($_FILES['archive']['name'] as $i => $name) { |
|
69
|
|
|
$this->name = $_FILES['archive']['name'][$i]; |
|
70
|
|
|
$this->size = $_FILES['archive']['size'][$i]; |
|
71
|
|
|
$this->type = $_FILES['archive']['type'][$i]; |
|
72
|
|
|
$this->tmp = $_FILES['archive']['tmp_name'][$i]; |
|
73
|
|
|
|
|
74
|
|
|
$this->explode = explode('.', $name); |
|
75
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param null $dir |
|
|
|
|
|
|
83
|
|
|
*/ |
|
84
|
|
|
public function file($dir = null) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->dir = $dir; |
|
87
|
|
|
|
|
88
|
|
|
$this->make(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return string |
|
93
|
|
|
*/ |
|
94
|
|
|
private function make() |
|
95
|
|
|
{ |
|
96
|
|
|
$this->makePathBayUserName(); |
|
97
|
|
|
$this->makeDefaultPath(); |
|
98
|
|
|
$this->makePathDirIfDefaultFileNotExist(); |
|
99
|
|
|
return $this->move_upload(); |
|
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
private function makePathDirIfDefaultFileNotExist() |
|
105
|
|
|
{ |
|
106
|
|
|
|
|
107
|
|
|
if (!file_exists(DIR_FILE . 'Upload' . DS . 'Default' . DS . $this->dir . DS)) { |
|
|
|
|
|
|
108
|
|
|
mkdir(DIR_FILE . 'Upload' . DS . 'Default' . DS . $this->dir . DS, 0755, true); |
|
109
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
private function move_upload() |
|
114
|
|
|
{ |
|
115
|
|
|
var_dump($this->path); |
|
|
|
|
|
|
116
|
|
|
move_uploaded_file($this->tmp, $this->path); |
|
117
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
private function makeDefaultPath() |
|
121
|
|
|
{ |
|
122
|
|
|
$this->path = DIR_FILE . 'Upload' . DS . 'Default' . DS . $this->dir . DS; |
|
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
private function makePathBayUserName() |
|
127
|
|
|
{ |
|
128
|
|
|
$this->ext = end($this->explode); |
|
129
|
|
|
$this->path .= basename($this->explode[0] . time() . '.' . $this->ext); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
} |