-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathuploader.php
More file actions
87 lines (74 loc) · 1.91 KB
/
uploader.php
File metadata and controls
87 lines (74 loc) · 1.91 KB
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
<?php
/** This file is part of load.link (https://github.com/deuiore/load.link).
* View the LICENSE file for full license information.
**/
class Uploader
{
protected $conf;
protected $tmp_path;
protected $name;
protected $path;
protected $mime;
protected $ext;
protected $uid;
public function __construct($name, $tmp_path)
{
$this->conf = Config::get()->getSection('link');
$this->tmp_path = $tmp_path;
$name = str_replace('\\', '\\\\', $name);
$name = str_replace('"', '\"', $name);
$this->name = $name;
$this->ext = pathinfo($this->name, PATHINFO_EXTENSION);
$this->mime = Utils::detectMime($tmp_path, $this->ext);
$this->path = $this->conf['upload_dir'] . $this->name;
while (file_exists($this->path))
{
$this->path .= $this->conf['same_name_suffix'];
}
}
public function upload()
{
if (move_uploaded_file($this->tmp_path, $this->path))
{
try
{
$uid = DB::get()->addLink(
$this->path, $this->name, $this->mime);
}
catch (Exception $e)
{
return FALSE;
}
$this->uid = $uid;
return TRUE;
}
}
public function getUID()
{
return $this->uid;
}
public function getName()
{
return $this->name;
}
public function getMime()
{
return $this->mime;
}
public function getExt()
{
return $this->ext;
}
public function getLink()
{
if (!$this->uid)
{
throw new Err(Err::FATAL,
'UID not found.');
}
return Router::getURL() . $this->uid
. (($this->ext
&& Config::get()->getValue('link', 'show_extension')) ?
'.' . $this->ext : '');
}
}