This repository was archived by the owner on Oct 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupload.php
143 lines (117 loc) · 4.46 KB
/
upload.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/*
* Jyraphe, your web file repository
* Copyright (C) 2008 Julien "axolotl" BERNARD <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define('JYRAPHE_ROOT', dirname(__FILE__) . '/');
// Preparing the configuration.
$cfg = parse_ini_file('config.php', true);
$cfg = $cfg['Interface'];
// Preparing the language settings.
setlocale(LC_ALL, $cfg['lang']);
bindtextdomain($cfg['jyraphe_package'], JYRAPHE_ROOT . 'lib/locale');
textdomain($cfg['jyraphe_package']);
require(JYRAPHE_ROOT . 'libjyraphe/hConfig.php');
require(JYRAPHE_ROOT . 'libjyraphe/hUpload.php');
require(JYRAPHE_ROOT . 'libjyraphe/hFunctions.php');
hConfig::create();
if (in_array($_SERVER['REQUEST_METHOD'], array('POST', 'PUT'))) {
if (empty($_POST) && empty($_FILES)) {
// Get maximum size and meassurement unit
$max_str = ini_get('post_max_size');
$max = ini_get('post_max_size');
$unit = substr($max, -1);
if (!is_numeric($unit)) {
$max = substr($max, 0, -1);
}
// Convert to bytes
switch (strtoupper($unit)) {
case 'G':
$max *= 1024;
case 'M':
$max *= 1024;
case 'K':
$max *= 1024;
}
try {
// Assert the content length is within limits
$length = $_SERVER['CONTENT_LENGTH'];
if ($max < $length) {
throw new hException('Error : maximum content length size (' . $max_str . ') exceeded (filesize : ' . humanReadableFilesize($length) . '), exiting...');
}
}
catch(hException $e) {
if(showHtml()) {
echo '<div class="message error"><p>';
echo $e->getMessage();
echo '</p></div>';
} else {
echo $e->getMessage() . hConfig::getVar('endl') . hConfig::getVar('endl');
}
}
} else {
try {
$uploader = new hUpload();
$link = "";
$web_root = $cfg['web_root'];
error_log(var_export($_REQUEST, true));
if (!empty($_POST['options'])) {
$options = $_POST['options'];
} else {
$options = array(
'key' => '',
'email' => '',
'duration' => '-1',
);
}
// Checks if a file is being uploaded.
if($uploader->has_request()) {
$link = $uploader->upload($_FILES['file'], $options);
}
// Shows up the download link if a file was uploaded.
// Why the hell would a link be within a text box???
if($link != "") {
if(showHtml()) {
echo '<div class="message info">';
echo '<p>' . _('File uploaded! Click on the following link to get it :') . '</p>';
echo '<form>';
echo '<input type="text" id="url" name="url" readonly="true" value="' . $web_root . 'file-' . $link . '" style="width: 98%; " onclick="javascript:this.focus(); this.select();"/>';
echo '<br /><br /><a href="' . $web_root . 'file-' . $link . '">' . $web_root . 'file-' . $link . '</a>';
echo '</form>';
if($options['duration'] != hDuration::INFINITY) {
echo '<br />' . _('This file is valid until the following date :') . '<br /><strong>' . strftime('%c' ,time() + $options['duration']) . '</strong>';
}
echo '</div>';
} else {
echo $web_root . 'file-' . $link . hConfig::getVar('endl') . hConfig::getVar('endl');
if($options['duration'] != hDuration::INFINITY) {
echo _('This file is valid until the following date : ') . strftime('%c' ,time() + $options['duration']) . hConfig::getVar('endl') . hConfig::getVar('endl');
}
}
}
}
catch(hException $e) {
if(showHtml()) {
echo '<div class="message error"><p>';
echo $e->getMessage();
echo '</p></div>';
} else {
echo $e->getMessage() . hConfig::getVar('endl') . hConfig::getVar('endl');
}
}
}
}
?>