|
1
|
|
|
<?php |
|
2
|
|
|
namespace samsonphp\upload; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Created by PhpStorm. |
|
6
|
|
|
* User: onysko |
|
7
|
|
|
* Date: 09.02.2015 |
|
8
|
|
|
* Time: 14:37 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class ServerHandler |
|
13
|
|
|
* @package samsonphp\upload |
|
14
|
|
|
*/ |
|
15
|
|
|
class AsyncHandler implements iHandler |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var $fs \samsonphp\fs\FileService Pointer to module controller */ |
|
18
|
|
|
public $fs; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Server Handler constructor |
|
22
|
|
|
* @param null $fs FileSystem module |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct($fs = null) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->fs = isset($fs) ? $fs : m('fs'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Get file name from $_SERVER array |
|
31
|
|
|
* @param string $name Name of post file (for using $_FILES array) |
|
32
|
|
|
* @return string Name of uploaded file |
|
33
|
|
|
*/ |
|
34
|
|
|
public function name($name = null) |
|
35
|
|
|
{ |
|
36
|
|
|
return urldecode($_SERVER['HTTP_X_FILE_NAME']); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Get file size from $_SERVER array |
|
41
|
|
|
* @param string $name Name of post file (for using $_FILES array) |
|
42
|
|
|
* @return integer Size of uploaded file |
|
43
|
|
|
*/ |
|
44
|
|
|
public function size($name = null) |
|
45
|
|
|
{ |
|
46
|
|
|
return $_SERVER['HTTP_X_FILE_SIZE']; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get file type from $_SERVER array |
|
51
|
|
|
* @param string $name Name of post file (for using $_FILES array) |
|
52
|
|
|
* @return string Mime type of uploaded file |
|
53
|
|
|
*/ |
|
54
|
|
|
public function type($name = null) |
|
55
|
|
|
{ |
|
56
|
|
|
return $_SERVER['HTTP_X_FILE_TYPE']; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get file content from php input socket |
|
61
|
|
|
* @param string $name Name of post file (for using $_FILES array) |
|
62
|
|
|
* @return string File content |
|
63
|
|
|
*/ |
|
64
|
|
|
public function file($name = null) |
|
65
|
|
|
{ |
|
66
|
|
|
return file_get_contents('php://input'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Write file in servers file system |
|
71
|
|
|
* @param $file mixed File content |
|
72
|
|
|
* @param $fileName string File name |
|
73
|
|
|
* @param $uploadDir string Catalog for uploading on server |
|
74
|
|
|
* @return bool|string Path to file or false if some errors found |
|
75
|
|
|
*/ |
|
76
|
|
|
public function write($file, $fileName, $uploadDir) |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->fs->write($file, $fileName, $uploadDir); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|