-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.php
129 lines (116 loc) · 4.13 KB
/
class.php
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
include "include/connect.php";
function HasLastSlash($content)
{
$loc = $content;
$last_slash = (substr($content, strlen($content) - 1, 1) == "/");
if (!$last_slash) {
$loc = ($content . "/");
}
return $loc;
}
class multiple_upload
{
public $uploaddir;
public $max_files;
public $max_size;
public $permission;
public $show;
public $files;
public $allowed = array();
public $notallowed = array();
public $errors = array();
public $cid;
public $domid;
public $sequel;
public $bilang;
public function get_filename($filename)
{
$filename = $filename;
return $filename;
}
public function multiple_upload()
{
//preset some values
$this->uploaddir = "uploads";
$this->max_files = 1;
$this->max_size = 10000;
$this->permission = 0777;
$this->allowed = array();
$this->notallowed = array();
$this->show = false;
}
public function validate()
{
$num = count($this->files['file']['name']);
//Control for max_files
if ($num > $this->max_files) {
$this->errors[0][] = "To many files! max allowed=" . $this->max_files;
return false;
} else {
//check for all files, SIZE and FILE_TYPE
for ($i = 0; $i < $num; $i++) {
//Check SIZE
if ($this->files['file']['size'][$i] > $this->max_size) {
$this->errors[1][] = "File: " . $this->files['file']['name'][$i] .
" size: " . $this->files['file']['size'][$i] .
" not allowed Max=: " .
($this->max_size / 1000) . " kb";
}
//split file-type information (image/gif)
$file_type = split('[/.-]', $this->files['file']['type'][$i]);
//Check if file-type ALLOWED
if (in_array($file_type[1], $this->allowed)) {
$this->errors[2][] = "File: " . $this->files['file']['name'][$i] .
" type: " . $this->files['file']['type'][$i] .
" not in list allowed";
//else Check if file-type NOT ALLOWED
} else if (in_array($file_type[1], $this->notallowed)) {
$this->errors[2][] = "File: " . $this->files['file']['name'][$i] .
" type: " . $this->files['file']['type'][$i] .
" not allowed";
}
}
if (count($this->errors) > 0) {
return false;
}
}
return true;
}
public function execute()
{
// echo "<html>En nu ? " . print_r($this) . "</html>";
//Get directory
$remdir = $this->uploaddir;
//Add when nessecary a slash
$remdir = HasLastSlash($remdir);
//Is dir writeable
if (!is_writable($remdir)) {
$this->errors[0][] = "Not allowed to write to dir:" . $remdir;
return false;
}
$num = count($this->files['file']['name']);
//Control for max_files
if ($num > $this->max_files) {
$this->errors[0][] = "To many files! max allowed=" . $this->max_files;
return false;
} else {
//====
//check for all files, SIZE and FILE_TYPE
for ($i = 0; $i < $num; $i++) {
$filename = $this->files['file']['name'][$i];
//$this->errors[0][] = $filename;
if (!empty($filename)) { // this will check if any blank field is entered
$add = $remdir . $filename; // upload directory path is set
if (is_uploaded_file($this->files['file']['tmp_name'][$i])) {
move_uploaded_file($this->files['file']['tmp_name'][$i], $add);
//echo $filename;
$sql = "UPDATE settings set logo='$filename'";
mysql_query($sql) or die("cant execute query!z" . mysql_error());
}
}
}
return true;
}
}
}