2011-02-09 17:57:10 +01:00
< ? php
2011-10-09 23:28:18 -07:00
//! delete
2011-02-09 17:57:10 +01:00
/** Edit fields ending with " _path " by < input type = " file " > and link to the uploaded files from select
2015-09-08 09:23:25 -07:00
* @ link https :// www . adminer . org / plugins / #use
2017-02-27 13:43:33 +01:00
* @ author Jakub Vrana , https :// www . vrana . cz /
2018-01-14 11:03:54 +01: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 17:57:10 +01:00
*/
2025-04-07 16:32:57 +02:00
class AdminerFileUpload extends Adminer\Plugin {
2025-03-11 07:21:13 +01:00
protected $uploadPath , $displayPath , $extensions ;
2013-07-24 16:26:41 -07:00
2011-02-09 17:57:10 +01:00
/**
2025-03-28 07:06:34 +01:00
* @ param string $uploadPath prefix for uploading data ( create writable subdirectory for each table containing uploadable fields )
* @ param string $displayPath prefix for displaying data , null stands for $uploadPath
* @ param string $extensions regular expression with allowed file extensions
2011-02-09 17:57:10 +01:00
*/
2025-04-01 19:09:46 +02:00
function __construct ( $uploadPath = " ../static/data/ " , $displayPath = null , $extensions = " [a-zA-Z0-9]+ " ) {
2011-02-09 17:57:10 +01:00
$this -> uploadPath = $uploadPath ;
2012-05-13 23:54:07 -07:00
$this -> displayPath = ( $displayPath !== null ? $displayPath : $uploadPath );
2011-10-09 23:28:18 -07:00
$this -> extensions = $extensions ;
2011-02-09 17:57:10 +01:00
}
2013-07-24 16:26:41 -07:00
2011-02-09 17:57:10 +01:00
function editInput ( $table , $field , $attrs , $value ) {
2013-07-24 16:26:41 -07:00
if ( preg_match ( '~(.*)_path$~' , $field [ " field " ])) {
2018-02-06 11:57:02 +01:00
return " <input type='file' $attrs > " ;
2011-02-09 17:57:10 +01:00
}
}
2013-07-24 16:26:41 -07:00
2011-02-09 17:57:10 +01:00
function processInput ( $field , $value , $function = " " ) {
2013-07-24 16:26:41 -07:00
if ( preg_match ( '~(.*)_path$~' , $field [ " field " ], $regs )) {
2011-02-09 17:57:10 +01:00
$table = ( $_GET [ " edit " ] != " " ? $_GET [ " edit " ] : $_GET [ " select " ]);
$name = " fields- $field[field] " ;
2013-07-24 16:26:41 -07:00
if ( $_FILES [ $name ][ " error " ] || ! preg_match ( " ~( \\ .( $this->extensions ))? \$ ~ " , $_FILES [ $name ][ " name " ], $regs2 )) {
2011-02-09 17:57:10 +01:00
return false ;
}
//! unlink old
2025-02-18 08:26:07 +01:00
$filename = ( function_exists ( 'random_bytes' ) ? bin2hex ( random_bytes ( 8 )) : uniqid ( " " , true )) . $regs2 [ 0 ];
2011-02-09 17:57:10 +01:00
if ( ! move_uploaded_file ( $_FILES [ $name ][ " tmp_name " ], " $this->uploadPath $table / $regs[1] - $filename " )) {
return false ;
}
2025-03-05 11:40:56 +01:00
return Adminer\q ( $filename );
2011-02-09 17:57:10 +01:00
}
}
2013-07-24 16:26:41 -07:00
2014-01-10 21:32:07 -08:00
function selectVal ( $val , & $link , $field , $original ) {
2018-02-20 16:02:25 +01:00
if ( $val != " " && preg_match ( '~(.*)_path$~' , $field [ " field " ], $regs )) {
2011-02-09 17:57:10 +01:00
$link = " $this->displayPath $_GET[select] / $regs[1] - $val " ;
}
}
2025-04-07 17:00:59 +02:00
2025-04-08 12:57:03 +02:00
protected $translations = array (
2025-04-07 17:00:59 +02:00
'cs' => array ( '' => 'Políčka končící na "_path" upravuje pomocí <input type="file"> a odkazuje na nahrané soubory z výpisu' ),
'de' => array ( '' => 'Bearbeiten Sie Felder, die mit "_path" enden, um <input type="file"> und verknüpfen Sie sie mit den hochgeladenen Dateien beim Select' ),
'pl' => array ( '' => 'Edytuj pola kończące się na "_path" za pomocą <input type="file"> i link do przesłanych plików z wybierz' ),
'ro' => array ( '' => 'Modificați câmpurile care se termină cu "_path" prin <input type="file"> și creați un link către fișierele încărcate din select' ),
2025-04-08 19:34:12 +09:00
'ja' => array ( '' => '列名が "_path" で終わる列を <input type="file"> で変更し、"選択" からアップロードされたファイルにリンク' ),
2025-04-07 17:00:59 +02:00
);
2011-02-09 17:57:10 +01:00
}