[091a4d]: plugins / file-upload.php Maximize Restore History

Download this file

file-upload.php    54 lines (47 with data), 1.9 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
<?php
//! delete
/** Edit fields ending with "_path" by <input type="file"> and link to the uploaded files from select
* @link http://www.adminer.org/plugins/#use
* @author Jakub Vrana, http://www.vrana.cz/
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerFileUpload {
/** @access protected */
var $uploadPath, $displayPath, $extensions;
/**
* @param string prefix for uploading data (create writable subdirectory for each table containing uploadable fields)
* @param string prefix for displaying data, null stands for $uploadPath
* @param string regular expression with allowed file extensions
*/
function AdminerFileUpload($uploadPath = "../static/data/", $displayPath = null, $extensions = "[a-zA-Z0-9]+") {
$this->uploadPath = $uploadPath;
$this->displayPath = ($displayPath !== null ? $displayPath : $uploadPath);
$this->extensions = $extensions;
}
function editInput($table, $field, $attrs, $value) {
if (ereg('(.*)_path$', $field["field"])) {
return "<input type='file' name='fields-$field[field]'>";
}
}
function processInput($field, $value, $function = "") {
if (ereg('(.*)_path$', $field["field"], $regs)) {
$table = ($_GET["edit"] != "" ? $_GET["edit"] : $_GET["select"]);
$name = "fields-$field[field]";
if ($_FILES[$name]["error"] || !ereg("(\\.($this->extensions))?\$", $_FILES[$name]["name"], $regs2)) {
return false;
}
//! unlink old
$filename = uniqid() . $regs2[0];
if (!move_uploaded_file($_FILES[$name]["tmp_name"], "$this->uploadPath$table/$regs[1]-$filename")) {
return false;
}
return q($filename);
}
}
function selectVal($val, &$link, $field) {
if ($val != "&nbsp;" && ereg('(.*)_path$', $field["field"], $regs)) {
$link = "$this->displayPath$_GET[select]/$regs[1]-$val";
}
}
}