473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

file size using javascript

58
hi friends,can any one give the coding for finding file size
using java script???
Mar 17 '07 #1
4 3582
mrhoo
428 256MB
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
gsuns82
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
gsuns82
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
r035198x
13,262 8TB
Threads merged.
Mar 19 '07 #5

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

Similar topics

4
by: Yaron Cohen | last post by:
Hi, I would like to ask for you help. I have a page that contains few JS files (please see below). The problem is that sometimes one of the files is not loaded (I am using IE 5.5). I get...
12
by: Ken | last post by:
How can I determine a image file size before uploading it? I would like to make sure the size is under a maximum before taking the time to upload it. If I have to upload the file before...
2
by: Ruskin | last post by:
I have developed an upload tool, that allows users to upload files (funny that). The asp form object has a 'SizeLimit' property that can be set, to prevent files being uploaded, that are too large....
2
by: tgundeck | last post by:
Does anyone know how I can check the file size of photos or any file type in JavaScript? I'm allowing users to store photos in my web page using the input type = file tag, but need to limit the...
19
by: pamelafluente | last post by:
Hi Guys, I am trying to include my little script in my html report. I have done an external JS file which contains it. If you remember, you have helped me to detect if the asp page was present...
13
by: marfola | last post by:
I’m trying to find the file size using javascript, before it get uploaded into the server using the following Javascript (I don’t want to use ActiveX because of compatibility problem). function...
1
by: chrisj | last post by:
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully. In this modified version there are two groups that use this upload script. Members of one...
4
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
3
Frinavale
by: Frinavale | last post by:
Hi there! I'm hoping that someone knows how to check the size of a file before it is uploaded to the server using JavaScript. I have seen suggested solutions using an ActiveX control to check...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.