I want to use code from this page
docs.dhtmlx.com/doku.php?id=dhtm … htmlxvault
I’m interested in exactly this code
<div id="vaultDiv"></div>
<script>
vault=new dhtmlXVaultObject();
vault.setImagePath("codebase/imgs/");
vault.setServerHandlers("UploadHandler.php", "GetInfoHandler.php", "GetIdHandler.php");
vault.onUploadComplete = function(files) {
var s="";
for (var i=0; i<files.length; i++) {
var file = files[i];
s += ("id:" + file.id + ",name:" + file.name + ",uploaded:" + file.uploaded + ",error:" + file.error)+"\n";
}
alert(s);
};
vault.create("vaultDiv");
</script>
One change, which wants to add it is
<div id="vaultDiv"></div>
<script>
vault=new dhtmlXVaultObject();
vault.setImagePath("codebase/imgs/");
vault.setServerHandlers("UploadHandler.php", "GetInfoHandler.php", "GetIdHandler.php");
vault.onUploadComplete = function(files) {
var s="";
for (var i=0; i<files.length; i++) {
var file = files[i];
s += ("id:" + file.id + ",size:" + file.size + ",name:" + file.name + ",uploaded:" + file.uploaded + ",error:" + file.error)+"\n";
}
alert(s);
};
vault.create("vaultDiv");
</script>
And i allways get “size:undefined”
Thanks for help
Fedor
November 9, 2011, 1:29pm
#2
There is no file size information on the client side.
So how can I get the size of the file to be added?
Fedor
November 9, 2011, 2:10pm
#4
You need to pass this information form the server. So you need to change server side scripts.
I do not understand something. Here, for example, I get the file size.
<!doctype html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title>File(s) size</title>
<script type="text/javascript">
function updateSize() {
var nBytes = 0, oFiles = document.getElementById("uploadInput").files, nFiles = oFiles.length;
for (var nFileId = 0; nFileId < nFiles; nFileId++) {
nBytes += oFiles[nFileId].size;
}
var sOutput = nBytes + " bytes";
// optional code for multiples approximation
for (var aMultiples = ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"], nMultiple = 0, nApprox = nBytes / 1024; nApprox > 1; nApprox /= 1024, nMultiple++) {
sOutput = nApprox.toFixed(3) + " " + aMultiples[nMultiple] + " (" + nBytes + " bytes)";
}
// end of optional code
// alert(nBytes);
document.getElementById("fileNum").innerHTML = nFiles;
document.getElementById("fileSize").innerHTML = sOutput;
}
</script>
</head>
<body onload="updateSize();">
<form name="uploadForm">
<p><input id="uploadInput" type="file" name="myFiles" onchange="updateSize();" multiple="multiple" /> selected files: <span id="fileNum">0</span>; total size: <span id="fileSize">0</span></p>
<p><input type="submit" value="Send file" /></p>
</form>
</body>
</html>
I do not understand how once javascript can show such a result and not the second time?
Fedor
November 9, 2011, 2:40pm
#6
That’s true, it works in some browsers, but does not work in IE. Should we add this function in the next release.
Yes, but I do not want to use IE and Mozilla only and exclusively. I do not understand why the same functionality js works, and using dhtmlx not?
Fedor
November 10, 2011, 8:29am
#8
This is because in the event handler we expose our own file object.
Good that you can stay without IE, not everyone agrees on that.
As i said, we will add size property to the next release.