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 can work in 4 modes, the best mode for corresponding browser detected automatically:
if (@$_REQUEST["mode"] == "conf") {
header("Content-Type: text/json");
print_r('{maxFileSize: 1234567}');
}
If maxFileSize was not set via config on init stage and server returned valid numeric maxFileSize greater than zero in conf-response, Vault will use maxFileSize returned by conf-response.
if (@$_REQUEST["mode"] == "html5" || @$_REQUEST["mode"] == "flash") {
if (@$_REQUEST["zero_size"] == "1") {
// IE10, IE11 zero file fix
// get file name
$filename = @$_REQUEST["file_name"];
// just create empty file
file_put_contents("path_to_save/".$filename, "");
} else {
// get file name
$filename = $_FILES["file"]["name"];
// save file
move_uploaded_file($_FILES["file"]["tmp_name"], "path_to_save/".$filename);
}
// response
header("Content-Type: text/json");
print_r(json_encode(array(
"state" => true, // saved or not saved
"name" => $filename, // server-name
"extra" => array( // extra info, optional
"info" => "just a way to send some extra data",
"param" => "some value here"
)
)));
}
if (@$_REQUEST["mode"] == "html4") {
header("Content-Type: text/html");
if (@$_REQUEST["action"] == "cancel") {
// handle cancelling
print_r('{"state":"cancelled"}');
} else {
// handle uploading
// get file name
$filename = $_FILES["file"]["name"];
// save file
move_uploaded_file($_FILES["file"]["tmp_name"], "path_to_file/".$filename);
print_r(json_encode(array(
"state" => true, // uploaded or not
"name" => $filename, // server-name
"size" => $_FILES["file"]["size"], // file size
"extra" => array( // extra info, optional
"info" => "just a way to send some extra data",
"param" => "some value here"
)
)));
}
}
if (@$_REQUEST["mode"] == "sl" && isset($_REQUEST["fileSize"]) && isset($_REQUEST["fileName"])
&& isset($_REQUEST["fileKey"])) {
// check key
preg_match("/^[a-z0-9]{12}$/", $_REQUEST["fileKey"], $p);
if (@$p[0] $_REQUEST["fileKey"]) {
// generate temp name
$temp_name = "path_to_file/".md5($p[0]);
if (@$_REQUEST["action"] != "getUploadStatus") {
// 1st "upload" request, no needs to output something
// saving file
$postData = file_get_contents("php://input");
if (strlen($postData) == $_REQUEST["fileSize"])
file_put_contents($temp_name, $postData);
} else {
// 2nd "check" request, output uploading status
$state = "false";
if (file_exists($temp_name)) {
rename($temp_name, "path_to_file/".$_REQUEST["fileName"]);
$state = "true";
}
header("Content-Type: text/json");
print_r(json_encode(array(
"state" => true, // uploaded or not
"name" => $_REQUEST["fileName"], // server-name
"extra" => array( // extra info, optional
"info" => "just a way to send some extra data",
"param" => "some value here"
)
)));
}
}
}
if (@$_REQUEST["mode"] == "custom") {
echo "{state: true, ".
"name: 'server_".str_replace("'", "\\'", $_REQUEST["name"])."', ".
"extra: {param: 'value'}}";
}
In order to download files from Vault you need to specify the path to the server.
You can do it in two ways:
1) set url to the server during the Vault initialization:
var myVault = new dhtmlXVaultObject({
downloadUrl: "../server/download.php?fileName={serverName}"
});
2) use the setDownloadURL method:
myVault.setDownloadURL("../server/download.php?fileName={serverName}");
{serverName} will be replaced with serverName attr, returned by server when file uploaded.
3) and finally some tricks on server side (script download.php):
<?php
// make sure file name set
if (isset($_REQUEST["fileName"])) {
// here you also can make some extra checks, like this
$fname = basename(urldecode($_REQUEST["fileName"]));
// get file contents
$data = file_get_contents("path/to/file/".$fname);
// send donwload headers, force browser to show download dialog
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$fname."\"");
header("Content-Length: ".strlen($data));
// output file
print_r($data);
}
?>
Back to top