2011-02-09 16:57:10 +00:00
|
|
|
<?php
|
2011-10-10 06:28:18 +00:00
|
|
|
//! delete
|
2011-02-09 16:57:10 +00:00
|
|
|
|
|
|
|
/** Edit fields ending with "_path" by <input type="file"> and link to the uploaded files from select
|
2015-09-08 16:23:25 +00:00
|
|
|
* @link https://www.adminer.org/plugins/#use
|
2017-02-27 12:43:33 +00:00
|
|
|
* @author Jakub Vrana, https://www.vrana.cz/
|
2018-01-14 10:03:54 +00:00
|
|
|
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
|
|
|
|
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
|
2011-02-09 16:57:10 +00:00
|
|
|
*/
|
|
|
|
class AdminerFileUpload {
|
2011-08-11 15:06:42 +00:00
|
|
|
/** @access protected */
|
2011-10-10 06:28:18 +00:00
|
|
|
var $uploadPath, $displayPath, $extensions;
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2011-02-09 16:57:10 +00:00
|
|
|
/**
|
|
|
|
* @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
|
2011-10-10 06:28:18 +00:00
|
|
|
* @param string regular expression with allowed file extensions
|
2011-02-09 16:57:10 +00:00
|
|
|
*/
|
2015-08-15 15:04:21 +00:00
|
|
|
function __construct($uploadPath = "../static/data/", $displayPath = null, $extensions = "[a-zA-Z0-9]+") {
|
2011-02-09 16:57:10 +00:00
|
|
|
$this->uploadPath = $uploadPath;
|
2012-05-14 06:54:07 +00:00
|
|
|
$this->displayPath = ($displayPath !== null ? $displayPath : $uploadPath);
|
2011-10-10 06:28:18 +00:00
|
|
|
$this->extensions = $extensions;
|
2011-02-09 16:57:10 +00:00
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2011-02-09 16:57:10 +00:00
|
|
|
function editInput($table, $field, $attrs, $value) {
|
2013-07-24 23:26:41 +00:00
|
|
|
if (preg_match('~(.*)_path$~', $field["field"])) {
|
2018-02-06 10:57:02 +00:00
|
|
|
return "<input type='file'$attrs>";
|
2011-02-09 16:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2011-02-09 16:57:10 +00:00
|
|
|
function processInput($field, $value, $function = "") {
|
2013-07-24 23:26:41 +00:00
|
|
|
if (preg_match('~(.*)_path$~', $field["field"], $regs)) {
|
2011-02-09 16:57:10 +00:00
|
|
|
$table = ($_GET["edit"] != "" ? $_GET["edit"] : $_GET["select"]);
|
|
|
|
$name = "fields-$field[field]";
|
2013-07-24 23:26:41 +00:00
|
|
|
if ($_FILES[$name]["error"] || !preg_match("~(\\.($this->extensions))?\$~", $_FILES[$name]["name"], $regs2)) {
|
2011-02-09 16:57:10 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2014-01-11 05:32:07 +00:00
|
|
|
function selectVal($val, &$link, $field, $original) {
|
2018-02-20 15:02:25 +00:00
|
|
|
if ($val != "" && preg_match('~(.*)_path$~', $field["field"], $regs)) {
|
2011-02-09 16:57:10 +00:00
|
|
|
$link = "$this->displayPath$_GET[select]/$regs[1]-$val";
|
|
|
|
}
|
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2011-02-09 16:57:10 +00:00
|
|
|
}
|