Check documentation for the latest version of dhtmlxSuite Managing the Files to Upload DHTMLX Docs

Managing the Files to Upload

This documentation is for Vault v2.5. Please go to docs.dhtmlx.com/vault/ to see documentation for the current version of dhtmlxVault.

The component allows you to control files that will be uploaded to the server. You can manage the allowable files' extensions, the maximum size of a file, the total allowable size of uploaded files and so on.

Controlling the files' extensions

To limit a list of allowable extensions, use the onBeforeFileAdd event. The event is blockable and returning false for a file will restrict its uploading to the server.

// allows uploading only files with the 'txt' and 'doc' extensions
var myVault = new dhtmlXVaultObject({...}); 
myVault.attachEvent("onBeforeFileAdd", function(file){
    var ext = this.getFileExtension(file.name);
    return (ext=="txt"||ext=="doc");
});

Controlling the number of uploaded files

To set the maximum number of files that can be uploaded to the server, use the setFilesLimit method as in:

// allows uploading only 4 files
myVault = new dhtmlXVaultObject({...});
myVault.setFilesLimit(4);

Controlling the size of a file to upload

To set the maximum size that a file can have to be uploaded to the server, use the onBeforeFileAdd event:

// restricts uploading files with the size is more than some value
var myVault = new dhtmlXVaultObject({...}); 
var allowableSize = 12345; // your choice
myVault.attachEvent("onBeforeFileAdd", function(file){
    if (file.size > allowableSize) return false; 
    return true;
});

Also there is a possibility to get server's max_file_size:

// restricts uploading files with the size more than the maximum size 
// allowed by the current server
var myVault = new dhtmlXVaultObject({...}); 
// returned by server, conf.uploadUrl with mode=conf
var maxSize = myVault.getMaxFileSize(); 
myVault.attachEvent("onBeforeFileAdd", function(file){
    if (file.size > maxSize) return false; 
    return true;
});

Controlling the total size of uploaded files

To set the maximum size of files that can be uploaded to the server, use the onBeforeFileAdd event:

// restricts uploading files if the total size of already uploaded files 
// exceeds 98765432 bytes
var myVault = new dhtmlXVaultObject({...}); 
var totalSize = 0;
var maxSize = 98765432; // your choice
myVault.attachEvent("onBeforeFileAdd", function(file){
    totalSize += file.size;
    if (totalSize > maxSize) return false; 
    return true;
});
Back to top