-
Notifications
You must be signed in to change notification settings - Fork 0
/
myupload.php
64 lines (58 loc) · 2.19 KB
/
myupload.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
<?php
namespace atk4\ui\FormField;
/**
*
*/
class MyUpload extends Upload
{
public function init()
{
parent::init();
}
public function onDelete($fx = null)
{
if (is_callable($fx)) {
$this->hasDeleteCb = true;
if ($this->cb->triggered() && @$_POST['action'] === 'delete') {
$fileName = @$_POST['f_name'];
$this->cb->set(function () use ($fx, $fileName) {
$this->addJsAction(call_user_func_array($fx, [$fileName]));
return $this->jsActions;
});
}
}
}
public function onUpload($fx = null)
{
if (is_callable($fx)) {
$this->hasUploadCb = true;
if ($this->cb->triggered()) {
$action = @$_POST['action'];
if ($files = @$_FILES) {
//set fileId to file name as default.
$this->fileId = $files['file']['name'];
$_SESSION['name_file'] = $files['file']['name'];
$_SESSION['size_file'] = $files['file']['size'];
$_SESSION['tmp_file'] = $files['file']['tmp_name'];
$_SESSION['type_file'] = $files['file']['type'];
// display file name to user as default.
$this->setInput($this->fileId);
}
if ($action === 'upload' && !$files['file']['error']) {
$this->cb->set(function () use ($fx, $files) {
$this->addJsAction(call_user_func_array($fx, $files));
//$value = $this->field ? $this->field->get() : $this->content;
$this->addJsAction([
$this->js()->atkFileUpload('updateField', [$this->fileId, $this->getInputValue()]),
]);
return $this->jsActions;
});
} elseif ($action === null || isset($files['file']['error'])) {
$this->cb->set(function () use ($fx, $files) {
return call_user_func($fx, 'error');
});
}
}
}
}
}