+ Reply to Thread
Results 1 to 3 of 3

Thread: File attachments running into server filesize limits

  1. #1
    Join Date
    Dec 2008
    Posts
    11

    Default File attachments running into server filesize limits

    Howdy, all.

    Recently was setting up a form that allows the user to attach a file and ran into some odd behavior (or so it seemed at first). After noodling around I realized what the problem was. I searched around here and didn't find a similar situation, so I thought I'd post my "solution" and see if anyone had a better idea.

    so I set up a form to accept file attachments no larger than 2MB. No problem, as the server allowed 4MB uploads. Had it set to check that the file wasn't larger than 2MB, returning a error message if it was:
    Code:
    @IF@attachedFile@attachedFile#<2097152@@Maximum file upload size is 2MB.@
    Everything worked just peachy-keen until I uploaded a file larger than 4MB. At that point, there was no error message, and the form got processed "normally", but no attachment was sent.

    Huh?

    So obviously (now, but not at the time), the server was intercepting the uploaded files, seeing that it was larger than 4MB, and dumping it. This meant that as far as the script was concerned, nothing was being attached. No attachment, no need to check the size, move along: nothing more to see here.

    This has obvious problems, because the user may think their file made it. Nothing was saying otherwise.

    Obviously we can't get past the server file size limitation because the server is First in All Things. So how to handle this unpleasantness (server-side)? My solution:

    I added a checkbox for the user to tick, indicating they were attaching a file:
    Code:
    <input type="checkbox" name="fileAttached" value="SeeAttached" id="fileAttached" />
    Then this:
    Code:
    @IF@fileAttached=/SeeAttached/@@attachedFile@It appears you
    have indicated that you are including additional documentation. Please attach the file
    and resubmit the form. If you attached a file, please note that you are not
    permitted to attach files larger than 2MB, and the file attached has exceeded 4MB.
    that last sentence elimitates some silliness: if the user attached a file but it was too honkin' big, then that's a bit of clarification. ("Waddaya mean 'Attach the file'? I DID attach the file!") I may increase the attachment limit to 4MB just to make that tidier. Anyway, pretty clear what I'm doing there. "This box is checked but there ain't nothin' in the file field, so what up, d00d?"

    Ok, great, but this is still only halfway there. Obviously we don't want that checkbox to be required because not everyone is uploading something. But what if they upload without checking the box? So...:
    Code:
    @IF@attachedFile=/!^[]$@@fileAttached@It appears you have attached a file.
    Please go back and check the box indicating that a file is attached.@
    the problem with this, of course, is we're right back at the beginning: server intercepted file; server nuked file; form field is blank; user doesn't know file got stripped. (ok, it's silly, too.)

    If anyone has a better (less-kludgy or non-kludgy) solution around this awkwardness, I'd luuuuurve to hear about it!

    btw, unless I'm missing something (and I only hack at php, so yeah, prolly am) this bit:
    Code:
    attachedFile#<2097152
    appears to be checking if the attached file is SMALLER than 2MB. < is less-than, > is greater-than. so shouldn't it be
    Code:
    attachedFile#>2097152
    ?

  2. #2
    Join Date
    Mar 2004
    Posts
    2,224

    Default Re: File attachments running into server filesize limits

    the checkbox is a pretty good idea

    u could improve it with some javascript - disable the file upload field until the checkbox is checked; so it doesn't break browsers without js, use js to disable the upload field, then js to enable it when the checkbox is checked.

    u can also use a hidden field:
    HTML Code:
    <input type="hidden" name ="MAX_FILE_SIZE" value="2097152"> 
    that's a soft limit that php will check but i'm not sure whether it will be detected before the server chucks a large file away...worth a test

    HTML Code:
    @IF@attachedFile@attachedFile#<2097152@@Maximum file upload size is 2MB.@
    that acutally says "if file size < 209..., then OK, else report error" so the #< is right

  3. #3
    Join Date
    Dec 2008
    Posts
    11

    Thumbs up Re: File attachments running into server filesize limits

    Quote Originally Posted by crabtree View Post
    u could improve it with some javascript - disable the file upload field until the checkbox is checked; so it doesn't break browsers without js, use js to disable the upload field, then js to enable it when the checkbox is checked.
    very nice. I'll do that.
    Quote Originally Posted by crabtree View Post
    u can also use a hidden field:
    HTML Code:
    <input type="hidden" name ="MAX_FILE_SIZE" value="2097152"> 
    that's a soft limit that php will check but i'm not sure whether it will be detected before the server chucks a large file away...worth a test
    Yep, I tried that as well and the results were the same. Server precedes form. it sees the incoming file and dumps it, so formmail never sees the attachment.

    Good to know my kludgy hack is about the best solution to this so far. Seems not many have run into it, but if folks are allowing uploads, it's something to definitely be aware of.

    Quote Originally Posted by crabtree View Post
    that acutally says "if file size < 209..., then OK, else report error" so the #< is right
    cool. thanks for clarifying.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Replies: 1
    Last Post: 13-Dec-2007, 09:54 PM
  2. Replies: 0
    Last Post: 13-Dec-2007, 05:08 AM
  3. Replies: 3
    Last Post: 21-Sep-2006, 12:44 AM
  4. Attachments / Exchange Server
    By TimW in forum Community Support
    Replies: 0
    Last Post: 17-May-2006, 12:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts