1: | <?php |
2: | |
3: | namespace Zippy\Html\Form; |
4: | |
5: | /** |
6: | * Компонент тэга <input type="file"> для загрузки файла |
7: | */ |
8: | class File extends HtmlFormDataElement |
9: | { |
10: | /** |
11: | * Конструктор |
12: | * @param mixed ID |
13: | */ |
14: | public function __construct($id, $multy = false) { |
15: | parent::__construct($id); |
16: | $this->setAttribute("name", $this->id); |
17: | if ($multy) { |
18: | $this->setAttribute("name", $this->id . '[]'); |
19: | $this->setAttribute("multiple", 'multiple'); |
20: | } |
21: | } |
22: | |
23: | /** |
24: | * Возвращает массив с описанием загруженного файла - элемент массива $_FILES |
25: | */ |
26: | public function getFile() { |
27: | return $this->getValue(); |
28: | } |
29: | |
30: | /** |
31: | * @see SubmitDataRequest |
32: | */ |
33: | public function getRequestData() { |
34: | if(!isset($_FILES[$this->id])) { |
35: | return; |
36: | } |
37: | |
38: | $this->setValue($_FILES[$this->id]); |
39: | } |
40: | |
41: | /* |
42: | public function setFile($path) { |
43: | |
44: | $files = array(); |
45: | if(!file_exists($path)) return; |
46: | $p = pathinfo($path); |
47: | $files['name'] = $p['basename']; |
48: | $files['size'] = filesize($path); |
49: | $tmp = tempnam(sys_get_temp_dir(),'tst'); |
50: | $files['tmp_name'] = $tmp; |
51: | copy($path,$tmp); |
52: | $this->setValue($files); |
53: | } */ |
54: | |
55: | |
56: | public function clean() { |
57: | |
58: | } |
59: | } |
60: |