By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,028 Members | 1,733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,028 IT Pros & Developers. It's quick & easy.

file size using javascript

P: 58
hi friends,can any one give the coding for finding file size
using java script???
Mar 17 '07 #1
Share this Question
Share on Google+
4 Replies


100+
P: 428
This method will find the filesize of files in the same domain as the calling page.
If no string is passed as an argument, the current page location is used.

call it like this: fetchSize(url)
Expand|Select|Wrap|Line Numbers
  1. function fetchSize(str){
  2.     if(!str)str=location.href;
  3.     var O= AJ(); //use your AJAX code, or AJ
  4.     if(!O) return false;
  5.     try{
  6.     O.open("HEAD", str, false); // NOT asynchronous
  7.     O.send(null);
  8.     if(O.status==200){
  9.     return O.getResponseHeader('Content-Length')+ ' bytes';    
  10.     }
  11.     else return false;
  12.     }
  13.     catch(er){
  14.     return false;
  15.     }
  16. }
  17.  
  18. function AJ(){
  19.     var obj;   
  20.     if (window.XMLHttpRequest) obj= new XMLHttpRequest();
  21.     else if (window.ActiveXObject) {
  22.     try{
  23.     obj= new ActiveXObject('MSXML2.XMLHTTP.3.0');
  24.     }
  25.     catch(er){
  26.     try{
  27.     obj=new ActiveXObject("Microsoft.XMLHTTP");
  28.     }
  29.     catch(er){
  30.     obj=false;
  31.     }
  32.     }
  33.      }
  34.       return obj;  
  35. }
Mar 17 '07 #2

P: 58
This method will find the filesize of files in the same domain as the calling page.
If no string is passed as an argument, the current page location is used.

call it like this: fetchSize(url)
Expand|Select|Wrap|Line Numbers
  1. function fetchSize(str){
  2.     if(!str)str=location.href;
  3.     var O= AJ(); //use your AJAX code, or AJ
  4.     if(!O) return false;
  5.     try{
  6.     O.open("HEAD", str, false); // NOT asynchronous
  7.     O.send(null);
  8.     if(O.status==200){
  9.     return O.getResponseHeader('Content-Length')+ ' bytes';    
  10.     }
  11.     else return false;
  12.     }
  13.     catch(er){
  14.     return false;
  15.     }
  16. }
  17.  
  18. function AJ(){
  19.     var obj;   
  20.     if (window.XMLHttpRequest) obj= new XMLHttpRequest();
  21.     else if (window.ActiveXObject) {
  22.     try{
  23.     obj= new ActiveXObject('MSXML2.XMLHTTP.3.0');
  24.     }
  25.     catch(er){
  26.     try{
  27.     obj=new ActiveXObject("Microsoft.XMLHTTP");
  28.     }
  29.     catch(er){
  30.     obj=false;
  31.     }
  32.     }
  33.      }
  34.       return obj;  
  35. }

hi thanks 4 replying,can u give me the code for finding the file size using java script while uploading a file from client side...
Mar 19 '07 #3

P: 58
hi friends,i need to find the file size using java script while
uploading at client side,can u people help me with exact
java script coding???
Mar 19 '07 #4

10K+
P: 13,264
Threads merged.
Mar 19 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.