I want to dynamically determine the capacity of volume to determine whether the file can be uploaded or not.
For example, when the capacity of volume is great than 200m, file will not to upload, and prompt the error message : "You have reached the maximum volume capacity"
how can I do?
sorry for my bad English, please help
@wzfjesun You can use connector option bind and volume option disabled, as one of the method.
for example (but not tested)
<?php
function isDiskFull() {
// must be return `true` if disk full
return true;
}
// bind callback for 'rm.pre'
function preCheckDiskFull($cmd, $args, $elfinder, $volume) {
$GLOBALS['prevFull'] = isDiskFull();
}
// bind callback for 'upload paste duplicate extract rm'
function checkDiskFull($cmd, $result, $args, $elfinder, $volume) {
$isFull = isDiskFull();
if ($cmd === 'rm') {
if (! $isFull && $GLOBALS['prevFull']) {
// request sync() to elFinder UI
return true;
}
} else {
if ($isFull) {
// request sync() to elFinder UI
return true;
}
}
}
$disableds = isDiskFull()? array('upload', 'paste', 'duplicate', 'extract', 'mkfile', 'mkdir') : array();
$opts = array(
'roots' => array(
array(
'driver' => 'LocalFileSystem',
'path' => '/path/to/files/',
'URL' => 'http://localhost/to/files/',
'disabled' => $disableds
)
),
// bind function for refresh elFinder UI
'bind' => array(
'rm.pre' => array('preCheckDiskFull').
'upload paste duplicate extract rm' => array('checkDiskFull')
),
// set disabled commands
'disabled' = $disableds
);
// run elFinder
$connector = new elFinderConnector(new elFinder($opts));
$connector->run();
Also, Probably #1524 will be help you.
Thanks for your quick reply.I will try it.
but how do I pop up a dialog to tell the user the capacity is full?Do you suggest me to use the status bar? Can I use a dialog like the file property dialog instead of the status bar?
how do I pop up a dialog to tell the user the capacity is full?
One of the example
// bind callback for 'upload paste duplicate extract rm'
function checkDiskFull($cmd, & $results) {
$isFull = isDiskFull();
if ($cmd === 'rm') {
if (! $isFull && $GLOBALS['prevFull']) {
// request sync() to elFinder UI
return true;
}
} else {
if ($isFull) {
// set custom data `_diskfull`
$results['_diskfull'] = true;
// request sync() to elFinder UI
return true;
}
}
}
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var elf = $('#elfinder').elfinder({
url : 'connector.php'
}).elfinder('instance');
elf.bind('upload paste duplicate extract', function(e) {
if (e.data._diskfull) {
elf.toast({
mode:'warning',
msg: 'Disk capacity is now full.',
hideDuration: 5000
});
}
});
});
</script>
I got the toast message now.
but when "Disk capacity is now full", the file still be uploaded.
how to prevent file being uploaded when Disk capacity is full?
I try:
'bind' => array(
'upload.pre' => array('myPreCheck'),
'rm.pre' => array('preCheckDiskFull'),
'upload paste duplicate extract rm' => array('checkDiskFull')
}
function myPreCheck($cmd, &$args, $elfinder, $volume)
{
$isFull = isDiskFull();
if ($isFull) {
// prevent uploading...
return false;
}else{
// do uploading...
return true;
}
}
I try to bind "upload.pre" to stop uploading,but not work.
@wzfjesun Please try $args['FILES'] = array();.
function myPreCheck($cmd, &$args, $elfinder, $volume)
{
$isFull = isDiskFull();
if ($cmd === 'upload' && $isFull) {
// prevent uploading...
$args['FILES'] = array();
}
}
@nao-pon
I tried. the file can not be uploaded, and popup a error message. but the message is not what I want.

Can I modify the message in the funccion myPreCheck?
By the way: How can I get the capacity of the volume?
I tried. the file can not be uploaded, and popup a error message. but the message is not what I want.
It's impossible now, so I made a issue #1658. Please wait next version or nightly build.
By the way: How can I get the capacity of the volume?
Please it is obtained in your favorite way. You have the following options: If you get in the elFinder.
function myPreCheck($cmd, &$args, $elfinder, $volume)
{
$max = 500 * 1024 * 1024; // e.g. 500MB
$isFull = ($volume->size($volume->root()) > $max);
if ($cmd === 'upload' && $isFull) {
// prevent uploading...
$args['FILES'] = array();
}
}
@nao-pon
It's impossible now, so I made a issue #1658. Please wait next version or nightly build.
That would be nice. At the present, I have solved it in this way.#1467
thanks.
I updated latest nightly build. Please try next code with nightly.
function myPreCheck($cmd, &$args, $elfinder, $volume)
{
$isFull = isDiskFull();
if ($isFull) {
// prevent uploading...
return array('preventexec' => true);
}
}
Thank you!
It seems like still has a problem.
Can I set custom data into results of the function?
function myPreCheck($cmd, &$args, $elfinder, $volume)
{
$isFull = isDiskFull();
if ($isFull) {
// prevent uploading...
return array('preventexec' => true);
}
}
If can not set, how can I get the Error type of message in the client side, because the client side does not have the handle like 'upload.pre' to catch the return value, and when [uplode.pre] callback function return array('preventexec' => true) ,the [upload] callback function will not execute, So I can't get the error type. Maybe there are something I missed.
@wzfjesun You can show error dialog with next...
function myPreCheck($cmd, &$args, $elfinder, $volume)
{
$isFull = isDiskFull();
if ($isFull) {
// prevent uploading...
return array(
'preventexec' => true,
'results' => array('error' => 'Disk capacity is now full.')
);
}
}
case of toast message it require #1662.
function myPreCheck($cmd, &$args, $elfinder, $volume)
{
$isFull = isDiskFull();
if ($isFull) {
// prevent uploading...
return array(
'preventexec' => true,
'results' => array('_diskfull' => true)
);
}
}
elf.bind('uploadfail', function(e) {
if (e.data._diskfull) {
elf.toast({
mode:'warning',
msg: 'Disk capacity is now full.',
hideDuration: 5000
});
}
});
ok, thank you
Most helpful comment
@wzfjesun You can use connector option
bindand volume optiondisabled, as one of the method.for example (but not tested)
Also, Probably #1524 will be help you.