I would like to use Handlers / Add Event with javascript for creating file at elfinder file manager. I would like to save data at db. But Add Event doesn' t work when creating new file. And this event is working when there is already file with the same name. Can you give me an idea? Thank you in advance..
if (! require.defined('elFinderConfig')) {
define('elFinderConfig', {
defaultOpts : {
url : 'elfinder/php/connector.minimal.php',
handlers : {
add: function(event, fm){
var files = event.data.added;
var paths = [];
files.forEach(function(item){
paths.push('C:\\**\\elfinder\\' + fm.path(item.hash, true) + '\\' + fm.path(item.name, true));
});
$.ajax({
url:"elfinder/php/savePathsToJR.php",
type: "POST",
data: {userName: userName, paths: paths},
success: function(item){
}
});
},
},
});
}
We realise that problem stem from Access Function at connector.minimal.php. Our code is like below. We are controling authorization from database for user permitted to see file. If we cancel this function our Handlers Add Event is working correctly. Because it couldn't pass from Access Function, it doesn' t trigger to add event.
Access Function is
function access($attr, $path, $data, $volume, $isDir, $relpath) {
$username = $_SESSION['session_login'];
$serverName = "***";
$options = array( "UID" => "TestUser", "PWD" => "**", "Database" => "**", "CharacterSet"=>"UTF-8");
$conn = sqlsrv_connect($serverName, $options);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
$query = "Select permitted_file_path from USER_FILE_PATHS where username = '" . $username . "'";
$stmt = sqlsrv_query( $conn, $query);
if($stmt === false)
{
echo "Error in query preparation/execution.\n";
die(print_r( sqlsrv_errors(), true));
}
$permittedPaths = array();
while($row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC))
{
array_push($permittedPaths, $row['permitted_file_path']);
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
$compare = in_array($path,$permittedPaths) ? false : true;
$retVal = $compare ? $compare : null;
return $retVal;
}