/
ftp_upload_file.php
204 lines (167 loc) · 7.96 KB
/
ftp_upload_file.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
// ftp_upload_file.php
//
// SiT (Support Incident Tracker) - Support call tracking system
// Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
//
// This software may be used and distributed according to the terms
// of the GNU General Public License, incorporated herein by reference.
//
// FIXME needs i18n
// Author: Ivan Lucas <ivanlucas[at]users.sourceforge.net>
$permission = 44; // ftp publishing
require ('core.php');
require (APPLICATION_LIBPATH.'functions.inc.php');
// This page requires authentication
require (APPLICATION_LIBPATH.'auth.inc.php');
// External variables
$file = cleanvar($_REQUEST['file']);
$action = cleanvar($_REQUEST['action']);
$max_filesize = return_bytes($CONFIG['upload_max_filesize']);
if (empty($action))
{
include (APPLICATION_INCPATH . 'htmlheader.inc.php');
echo "<h2>Upload Public File</h2>";
echo "<p align='center'>IMPORTANT: Files published here are <strong>public</strong> and available to all ftp users.</p>";
echo "<form name='publishform' action='{$_SERVER['PHP_SELF']}' method='post' enctype='multipart/form-data'>";
echo "<table class='vertical'>";
echo "<tr><th>File <small>(<".readable_file_size($max_filesize).")</small>:</th>";
echo "<td class='shade2'><input type='hidden' name='MAX_FILE_SIZE' value='{$max_filesize}' />";
echo "<input type='file' name='file' size='40'' /></td></tr>";
echo "<tr><th>{$strTitle}:</th><td><input type='text' name='shortdescription' maxlength='255' size='40' /></td></tr>";
echo "<tr><th>{$strDescription}:</th><td><textarea name='longdescription' cols='40' rows='3'></textarea></td></tr>";
echo "<tr><th>{$strFileVersion}:</th><td><input type='text' name='fileversion' maxlength='50' size='10' /></td></tr>";
echo "<tr><th>{$strExpire}:</th><td>";
echo "<input type='radio' name='expiry_none' value='time'' /> In <em>x</em> days, hours, minutes<br /> ";
echo "<input maxlength='3' name='expiry_days' value='{$na_days}' onclick=\"window.document.publishform.expiry_none[0].checked = true;\" size='3'' /> Days ";
echo "<input maxlength='2' name='expiry_hours' value='{$na_hours}' onclick=\"window.document.publishform.expiry_none[0].checked = true;\" size='3'' /> Hours ";
echo "<input maxlength='2' name='expiry_minutes' value='{$na_minutes}' onclick=\"window.document.publishform.expiry_none[0].checked = true;\" size='3'' /> Minutes<br />";
echo "<input type='radio' name='expiry_none' value='date'' />On specified Date<br /> ";
// Print Listboxes for a date selection
echo "<select name='day' onclick=\"window.document.publishform.expiry_none[1].checked = true;\">";
for ($t_day=1;$t_day<=31;$t_day++)
{
echo "<option value=\"{$t_day}\" ";
if ($t_day == date("j"))
{
echo "selected='selected'";
}
echo ">$t_day</option>\n";
}
echo "</select><select name='month' onclick=\"window.document.publishform.expiry_none[1].checked = true;\">";
for ($t_month = 1; $t_month <= 12; $t_month++)
{
echo "<option value=\"{$t_month}\"";
if ($t_month == date("n"))
{
echo " selected='selected'";
}
echo ">". date ("F", mktime(0,0,0,$t_month,1,2000)) ."</option>\n";
}
echo "</select><select name='year' onclick=\"window.document.publishform.expiry_none[1].checked = true;\">";
for ($t_year = (date("Y")-1); $t_year <= (date("Y")+5); $t_year++)
{
echo "<option value=\"{$t_year}\" ";
if ($t_year == date("Y"))
{
echo "selected='selected'";
}
echo ">$t_year</option>\n";
}
echo "</select>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<p align='center'><input type='submit' value='{$strPublish}' />";
echo "<input type='hidden' name='action' value='publish' /></p>";
echo "<p align='center'><a href='ftp_list_files.php'>{$strBackToList}</a></p>";
echo "</form>";
include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
}
else
{
// echo "<pre>".print_r($_REQUEST,true)."</pre>";
// echo "<pre>".print_r($_FILES,true)."</pre>";
// TODO v3.2x ext variables
$file_name = $_FILES['file']['name'];
$shortdescription = cleanvar($_REQUEST['shortdescription']);
$longdescription = cleanvar($_REQUEST['longdescription']);
$fileversion = cleanvar($_REQUEST['fileversion']);
$expirytype = cleanvar($_REQUEST['expiry_none']);
if ($expirytype == 'time')
{
$days = cleanvar($_REQUEST['expiry_days']);
$hours = cleanvar($_REQUEST['expiry_hours']);
$minutes = cleanva($_REQUEST['expiry_minutes']);
if ($days < 1 && $hours < 1 && $minutes < 1)
{
$expirydate = 0;
}
else
{
$expirydate = calculate_time_of_next_action($days, $hours, $minutes);
}
}
elseif ($expirytype == 'date')
{
$day = cleanvar($_REQUEST['day']);
$month = cleanvar($_REQUEST['month']);
$year = cleanvar($_REQUEST['year']);
$date = explode("-", $date);
$expirydate = mktime(0, 0, 0, $month, $day, $year);
}
else
{
$expirydate = 0;
}
// receive the uploaded file to a temp directory on the local server
if ($_FILES['file']['error'] != '' AND $_FILES['file']['error'] != UPLOAD_ERR_OK)
{
echo get_file_upload_error_message($_FILES['file']['error'], $_FILES['file']['name']);
}
else
{
$filepath = $CONFIG['attachment_fspath'].$file_name;
$mv = move_uploaded_file($_FILES['file']['tmp_name'], $filepath);
if (!mv) trigger_error("Problem moving uploaded file from temp directory: {$filepath}", E_USER_WARNING);
if (!file_exists($filepath)) trigger_error("Error the temporary upload file ($file) was not found at: {$filepath}", E_USER_WARNING);
// Check file size
$filesize = filesize($filepath);
if ($filesize > $CONFIG['upload_max_filesize'])
{
trigger_error("User Error: Attachment too large or file ('.$file.') upload error - size: ".filesize($filepath), E_USER_WARNING);
// throwing an error isn't the nicest thing to do for the user but there seems to be no way of
// checking file sizes at the client end before the attachment is uploaded. - INL
}
if ($filesize == FALSE) trigger_error("Error handling uploaded file: {$file}", E_USER_WARNING);
// set up basic connection
$conn_id = create_ftp_connection();
$destination_filepath = $CONFIG['ftp_path'] . $file_name;
// check the source file exists
if (!file_exists($filepath)) trigger_error("Source file cannot be found: {$filepath}", E_USER_WARNING);
// set passive mode if required
if (!ftp_pasv($conn_id, $CONFIG['ftp_pasv'])) trigger_error("Problem setting passive ftp mode", E_USER_WARNING);
// upload the file
$upload = ftp_put($conn_id, "$destination_filepath", "$filepath", FTP_BINARY);
// close the FTP stream
ftp_close($conn_id);
// check upload status
if (!$upload)
{
trigger_error($strUploadFailed, E_USER_ERROR);
}
else
{
// store file details in database
// important: path must be blank for public files (all go in same dir)
$sql = "INSERT INTO `{$dbFiles}` (filename, size, userid, shortdescription, longdescription, path, filedate, expiry, fileversion) ";
$sql .= "VALUES ('$file_name', '$filesize', '".$sit[2]."', '$shortdescription', '$longdescription', '{$CONFIG['ftp_path']}', '$now', '$expirydate' ,'$fileversion')";
mysql_query($sql);
if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
journal(CFG_LOGGING_NORMAL, 'FTP File Uploaded', sprintf($strFTPFileXUploaded, $filename), CFG_JOURNAL_OTHER, 0);
html_redirect('ftp_upload_file.php');
echo "<code>{$ftp_url}</code>";
}
}
}
?>