1: <?php
2: 3: 4: 5: 6: 7:
8:
9: namespace GLFramework\Upload;
10:
11:
12: class Upload
13: {
14:
15: var $upload;
16: var $uploads;
17: var $hash;
18: 19: 20: 21: 22:
23: public function __construct($uploads, $upload)
24: {
25: $this->uploads = $uploads;
26: $this->upload = $upload;
27:
28: $this->hash = date("Y-m-d_H-i-s") . "_";
29: }
30:
31: public function isMultiple()
32: {
33: return is_array($this->upload['name']);
34: }
35:
36: public function getLength()
37: {
38: return count($this->upload['name']);
39: }
40:
41: public function getFilename($index = null)
42: {
43: return $this->uploads->folder . "/" . $this->hash . $this->name($index);
44: }
45:
46: public function getAbsolutePath($index = false)
47: {
48: return $this->uploads->dir . "/" . $this->getFilename($index);
49: }
50:
51: public function move($index = false)
52: {
53: $source = $this->tmpName($index);
54: $dest = $this->getAbsolutePath($index);
55: return move_uploaded_file($source, $dest);
56: }
57:
58: public function error($index = false)
59: {
60: if($index === false)
61: return $this->upload['error'];
62: return $this->upload['error'][$index];
63: }
64:
65: public function name($index = false)
66: {
67: if($index === false)
68: return $this->upload['name'];
69: return $this->upload['name'][$index];
70: }
71:
72: public function tmpName($index = false)
73: {
74: if($index === false)
75: return $this->upload['tmp_name'];
76: return $this->upload['tmp_name'][$index];
77: }
78:
79: public function isEmpty($index = false)
80: {
81: return $this->error($index) == 4;
82: }
83:
84: public function isSuccess($index = false)
85: {
86: return $this->error($index) == 0;
87: }
88:
89: }