Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 54 lines (47 sloc) 1.941 kB
4f9ff89 @vrana Plugins
authored
1 <?php
468644e @vrana Allowed extensions
authored
2 //! delete
4f9ff89 @vrana Plugins
authored
3
4 /** Edit fields ending with "_path" by <input type="file"> and link to the uploaded files from select
091a4d0 @vrana Link to documentation
authored
5 * @link http://www.adminer.org/plugins/#use
4f9ff89 @vrana Plugins
authored
6 * @author Jakub Vrana, http://www.vrana.cz/
7 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
8 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
9 */
10 class AdminerFileUpload {
7578342 @vrana Comment
authored
11 /** @access protected */
468644e @vrana Allowed extensions
authored
12 var $uploadPath, $displayPath, $extensions;
4f9ff89 @vrana Plugins
authored
13
14 /**
15 * @param string prefix for uploading data (create writable subdirectory for each table containing uploadable fields)
16 * @param string prefix for displaying data, null stands for $uploadPath
468644e @vrana Allowed extensions
authored
17 * @param string regular expression with allowed file extensions
4f9ff89 @vrana Plugins
authored
18 */
468644e @vrana Allowed extensions
authored
19 function AdminerFileUpload($uploadPath = "../static/data/", $displayPath = null, $extensions = "[a-zA-Z0-9]+") {
4f9ff89 @vrana Plugins
authored
20 $this->uploadPath = $uploadPath;
6591d48 @vrana Replace isset($var) by $var !== null
authored
21 $this->displayPath = ($displayPath !== null ? $displayPath : $uploadPath);
468644e @vrana Allowed extensions
authored
22 $this->extensions = $extensions;
4f9ff89 @vrana Plugins
authored
23 }
24
25 function editInput($table, $field, $attrs, $value) {
26 if (ereg('(.*)_path$', $field["field"])) {
27 return "<input type='file' name='fields-$field[field]'>";
28 }
29 }
30
31 function processInput($field, $value, $function = "") {
32 if (ereg('(.*)_path$', $field["field"], $regs)) {
33 $table = ($_GET["edit"] != "" ? $_GET["edit"] : $_GET["select"]);
34 $name = "fields-$field[field]";
468644e @vrana Allowed extensions
authored
35 if ($_FILES[$name]["error"] || !ereg("(\\.($this->extensions))?\$", $_FILES[$name]["name"], $regs2)) {
4f9ff89 @vrana Plugins
authored
36 return false;
37 }
38 //! unlink old
39 $filename = uniqid() . $regs2[0];
40 if (!move_uploaded_file($_FILES[$name]["tmp_name"], "$this->uploadPath$table/$regs[1]-$filename")) {
41 return false;
42 }
43 return q($filename);
44 }
45 }
46
47 function selectVal($val, &$link, $field) {
48 if ($val != "&nbsp;" && ereg('(.*)_path$', $field["field"], $regs)) {
49 $link = "$this->displayPath$_GET[select]/$regs[1]-$val";
50 }
51 }
52
53 }
Something went wrong with that request. Please try again.