Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining File Size 1

Status
Not open for further replies.

duckiebear

Programmer
May 25, 2004
32
0
0
US
I have a web application where users can upload files in a record with metadata about the file. Is there a way to determine the file size before the user opens the file, so I could notify the user "you are downloading a file that is XX MB, please ensure you have enough disk space before confirming the download".

Also, is there a way to check the file size of "to be uploaded" attachments before the record is saved to compare with the amount of available disk space on the server, so I can disallow a user from uploading a file if it will leave me with 10% or less disk space on the server?
 
You'll have to refer to the server side code that handles the form post of the file upload. There is no way for JavaScript, in a conventional world, to determine anything about the file system on the client.

ToddWW
 
You should do this server-side. The only way to determine the file size using JavaScript is if the file is an image:
Code:
function GetSize(file){
  var img = new Image();
  img.src=file;
  return img.fileSize;
}

Or by using ActiveX:
Code:
function GetSize(file){
  var fso = new ActiveXObject("Scripting.FileSystemObject"); 
  var f = fso.getFile(file);
  return f.size;
}

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
As far as downloading goes, you should definitely use server-side script. Using a client-side script, you'd have to download the file first to get its properties and since you only want to download the file based on one of its properties, it wouldn't make sense to do it this way.

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
Thanks, for all of the help. This is for a Video Library, so it will only be images being uploaded and downloaded. I will try the javascript function mention here on the server side.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top