• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7703
  • Last Modified:

Upload File Size Validation check without doing a page refresh

Is there a AJAX based solution or PHP based solution to check the filesize a user is trying to upload via a form.
If the filesize exceeds more than 2 MB we want to give a message to the user that they need to upload a smaller file size.

There are tons of Active X/Php solutions.

We want to avoid Active X

And when using PHP it refreshes the page, is there anyway we can check filesize on the fly without having to refresh the page.
0
Rondittmann
Asked:
Rondittmann
1 Solution
 
paulp75Commented:
just had a quick look. not sure if you could add something into a function with jquery plugin like this one.

http://www.fyneworks.com/jquery/multiple-file-upload/
0
 
sanjoozCommented:
<input type="file" name="somename" size="size in bytes">

You can use this to restrict the size. Unfortunately, you can not do this on client side without activex or signed applets. This is one of the security features.
0
 
Richard QuadlingSenior Software DeveloperCommented:
From my understanding of Javascript, you have no access to the files on the local harddrive.

Therefore, JS cannot send anything to the server about the requested file.

The reason you see the ActiveX components is that these are providing JS access to the file system (in some form and to various degrees).

But, having said all of that, something you could try is to use a packet sniffer to see exactly what is being sent by these ActiveX components and see if any of it can be replicated. I doubt you will get anything.

Thinking more about this, just imagine the security issues.

If you COULD use JS to AJAX a file from the local pc to the server, the nasty people would have a field day.

So, I would say that without the user loading a proprietary plugin, you are not going to be able to do this using native code (js/dom/etc).
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
steelseth12Commented:
It can be done using flash, which although IE loads using ActiveX i wouldn't classify it as you typical activex control and its available in other browsers i.e Firefox through NPAPI, and according to Adobe is the most widely used piece of software to date, I think 300,000,000 for flash player 8.

You can find alot of examples if you do a search in google.

http://www.saschawenning.de/labor/flash8/fileUpload/

http://www.masrizal.com/product/custom%20tag/cf_flashmultiupload/docs%20&%20examples/example.cfm

0
 
RondittmannAuthor Commented:
I need a solution which will check the filesize on the fly, and notify the end user if the size is larger than 2MB.

The last flash solution has an entire component for multi file upload. I just need 1 upload field, we cannot deploy the component in its current state.

Whatever method we deploy it also cannot be in Iframes.

0
 
Richard QuadlingSenior Software DeveloperCommented:
With regard to PHP, the $_FILES super global array is not populated until after the file upload has taken place.

So, as it stands (5.2.x), you cannot get the size of the upload until the upload has taken place.

The HTTP POST command does send a Content-length field.

Here is a grab from one of a test upload (see snippet below).

The actual file I sent is 29,090,344 bytes, so there is an overhead for the multipart.

The amount of overhead is dependent upon the filename and filetype and what boundary is used (that may be fixed, but different browsers may send different things).

I believe that PHP6 has some work on allowing you to get to the header before the main PHP code is run. Not exactly sure how.

I can't find the exact message on internals, maybe you can.


POST /indiv/franklin/cgi-bin/values HTTP/1.1
Host: www.oac.uci.edu
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9b2) Gecko/2007121120 Firefox/3.0b2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.7,en-us;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://hydra.nac.uci.edu/indiv/franklin/doc/file_upload.html
Content-Type: multipart/form-data; boundary=---------------------------265001916915724
Content-Length: 29090558
 
-----------------------------265001916915724
Content-Disposition: form-data; name="userfile"; filename="sp30767.exe"
Content-Type: application/x-msdos-program

Open in new window

0
 
CWS (haripriya)Commented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
   Accept: RQuadling {http:#20879398}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

cyberwebservice
Experts Exchange Cleanup Volunteer
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
 
paulp75Commented:
i know this is a bit late, but i came across this, which seems to validate the size before upload
http://www.pixeline.be/experiments/jqUploader/test.php
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Tackle projects and never again get stuck behind a technical roadblock.
Join Now