|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* APWEB Framework (http://framework.artphoweb.com/) |
|
6
|
|
|
* APWEB FW(tm) : Rapid Development Framework (http://framework.artphoweb.com/) |
|
7
|
|
|
* |
|
8
|
|
|
* Licensed under The MIT License |
|
9
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
|
10
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
11
|
|
|
* |
|
12
|
|
|
* @link http://github.com/zebedeu/artphoweb for the canonical source repository |
|
13
|
|
|
* @copyright (c) 2016. APWEB Software Technologies AO Inc. (http://www.artphoweb.com) |
|
14
|
|
|
* @license http://framework.artphoweb.com/license/new-bsd New BSD License |
|
15
|
|
|
* @author Marcio Zebedeu - [email protected] |
|
16
|
|
|
* @version 1.0.0 |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
class Uploads{ |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
private $files; |
|
|
|
|
|
|
24
|
|
|
public $path; |
|
25
|
|
|
private $tmp; |
|
26
|
|
|
public $name; |
|
27
|
|
|
public $size; |
|
28
|
|
|
public $type; |
|
29
|
|
|
private $dir; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
public function file($dir = null) { |
|
|
|
|
|
|
32
|
|
|
if (!empty($dir)) { |
|
33
|
|
|
if (isset($_FILES['archive'])) { |
|
34
|
|
|
foreach ($_FILES['archive']['name'] as $i => $name) { |
|
35
|
|
|
$this->name = $_FILES['archive']['name'][$i]; |
|
36
|
|
|
$this->size = $_FILES['archive']['size'][$i]; |
|
37
|
|
|
$this->type = $_FILES['archive']['type'][$i]; |
|
38
|
|
|
$this->tmp = $_FILES['archive']['tmp_name'][$i]; |
|
39
|
|
|
|
|
40
|
|
|
$explode = explode('.', $name); |
|
41
|
|
|
$ext = end($explode); |
|
42
|
|
|
|
|
43
|
|
|
$this->path = DIR_FILE . 'Upload' . DS . 'Default' . DS . $dir . DS; |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
$this->path .= basename($explode[0] . time() . '.' . $ext); |
|
46
|
|
|
$explode = explode('.', $name); |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
// echo $ext . "<br/>"; |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
if (empty($this->type)) { |
|
53
|
|
|
return $errors[] = '<div class="btn btn-danger"> Por favor, escolhe 1 ficheiro para ser carregado</div>'; |
|
|
|
|
|
|
54
|
|
|
} else { |
|
55
|
|
|
$allowed = array('jpg', 'JPG', 'jpeg', 'gif', 'btm', 'png', 'txt', 'docx', 'doc', 'pdf', 'mp3'); |
|
56
|
|
|
|
|
57
|
|
|
if (in_array($ext, $allowed) === false) |
|
58
|
|
|
return $errors[] = '<div class="btn btn-danger">A extensao do ficheiro nao foi permitido </div>'; |
|
59
|
|
|
} |
|
60
|
|
|
// 100000000 |
|
61
|
|
|
$max_size = 100000000; |
|
62
|
|
|
if ($this->size > $max_size) { |
|
63
|
|
|
return $errors[] = '<div class="btn btn-danger"> O tamanho do ficheiro é muito grande</div>'; |
|
64
|
|
|
} |
|
65
|
|
|
}// end foreach |
|
66
|
|
|
} // end if |
|
67
|
|
|
|
|
68
|
|
|
if (empty($errors)) { |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
if (!file_exists(DIR_FILE . 'Upload' . DS . $dir . DS)) { |
|
71
|
|
|
mkdir(DIR_FILE . 'Upload' . DS . $dir . DS, 0777, true); |
|
72
|
|
|
|
|
73
|
|
|
} // chmod('uploads/', 0755); |
|
|
|
|
|
|
74
|
|
|
else if (!file_exists(DIR_FILE . 'Upload' . DS . 'Default' . DS . $dir . DS)) { |
|
75
|
|
|
mkdir(DIR_FILE . 'Upload' . DS . 'Default' . DS . $dir . DS, 0777, true); |
|
76
|
|
|
|
|
77
|
|
|
} // chmod('uploads/', 0755); |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
if (move_uploaded_file($this->tmp, $this->path )) { |
|
80
|
|
|
$output = '<div class="btn btn-success">'; |
|
81
|
|
|
$output .= 'Ficheiro carregado com sucesso'; |
|
82
|
|
|
$output .= '</div>'; |
|
83
|
|
|
return $output; |
|
84
|
|
|
} else { |
|
85
|
|
|
$output = '<div class="btn btn-warning">'; |
|
86
|
|
|
$output .= 'Nenhum ficheiro foi carregado'; |
|
87
|
|
|
$output .= '</div>'; |
|
88
|
|
|
return $output; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
public function formUploadFiles($dir_rec = null, $type = "hidden", $name = null, $value = null) { |
|
96
|
|
|
$var = ""; |
|
97
|
|
|
$var .= "<form method='POST' enctype='multipart/form-data' action='" . $dir_rec . "'>"; |
|
98
|
|
|
$var .= "<input type='hidden' name=' ini_get('session.upload_progress.name'); ' value='123' />"; |
|
99
|
|
|
|
|
100
|
|
|
$var .= "<input type='file' name='archive[]' multiple ><br/>"; |
|
101
|
|
|
$var .= "<input type='$type' name='$name' value='$value'> <br/>"; |
|
102
|
|
|
$var .= "<button type='submit' class=' btn btn-lg btn-default glyphicon glyphicon-upload'></button></form>"; |
|
103
|
|
|
return $var; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.