From cc5aad1168ff68c6ed1598f1d8f7ce8d49f3a890 Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Wed, 23 Nov 2022 11:09:06 +0100 Subject: [PATCH] Allow defining an upload callback --- tinyfilemanager.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tinyfilemanager.php b/tinyfilemanager.php index a25bc11..eae71d0 100644 --- a/tinyfilemanager.php +++ b/tinyfilemanager.php @@ -132,6 +132,13 @@ $ip_blacklist = array( '::' // non-routable meta ipv6 ); +// A callable that can be called when a file is uploaded. +// We'll send it 2 arguments: +// 1. a string containing the absolute path of the file uploaded +// 2. an array with the default response data +// It can return null or an array: in this second case it's the customized response data +$uploadCallback = null; + // if User has the customized config file, try to use it to override the default config above // sample config - https://tinyfilemanager.github.io/config-sample.txt $config_file = __DIR__.'/config.php'; @@ -977,6 +984,9 @@ if (!empty($_FILES) && !FM_READONLY) { if ($chunkIndex == $chunkTotal - 1) { rename("{$fullPath}.part", $fullPath); + if (is_callable($uploadCallback)) { + $response = call_user_func($uploadCallback, $fullPath, $response) ?: $response; + } } } else if (move_uploaded_file($tmp_name, $fullPath)) { @@ -986,6 +996,9 @@ if (!empty($_FILES) && !FM_READONLY) { 'status' => 'success', 'info' => "file upload successful" ); + if (is_callable($uploadCallback)) { + $response = call_user_func($uploadCallback, $fullPath, $response) ?: $response; + } } else { $response = array ( 'status' => 'error',