0

I'm using a form to upload a file but want to limit the max size people upload and show an error message if it goes above a set limit!

I've researched and tried various methods but nothing seems to work.

This is what I have so far;

if (jQuery(".uploaded_file")[0].files[0].size / 1) {
    error = true;
    error_message.push('File is too big, please make smaller.');
    this.value = "";
};

Not sure if I need to do something beforehand because I keep getting Cannot read property 'size' of undefined

Sam
  • 41
  • 1
  • 8
  • Sorry not following - control? I've used `` and using PHPMailer to process it? Hope that helps thanks – Sam Nov 24 '17 at 11:09
  • Brilliant, how is it done? – Sam Nov 24 '17 at 11:14
  • take a look at Mark.Inmans answer on this question: https://stackoverflow.com/questions/5697605/limit-the-size-of-an-file-upload-html-input/17173301#17173301. The best solution however is to validate the file size Server side rather than client side. – Master Yoda Nov 24 '17 at 11:15
  • They don't help? They all give you the file size which I can already do, what I'm trying to do is show an alert if the file size is above 10mb for example? – Sam Nov 24 '17 at 11:26
  • I have done! It clearly says I want an alert to appear if above a file size? Even the code example shows I'm looking for an error message to appear not the file size. – Sam Nov 24 '17 at 11:28

0 Answers0