Upload HTML5

  • Posts: 2461
  • Karma: 86
  • Thank you received: 333

mihaela replied the topic: Upload HTML5

Hmm, I don't understand why it uploads the files in your case.

I've made at least 10 tests and here is how it works.

I have "Use HTML5 upload" checked. "Allow multi HTML5/Flash uploads" and "Use Flash upload (legacy)" are not checked.

As "HTML5/Flash max. filesize in bytes (0 = no limit)" I've put the same number as in the "BEGIN Submit" pieces.

So, I first submit the file too big, the error message shows and it isn't saved or uploaded.

Actually, I think that maybe this didn't work when I've tested before one change I've made.

In php.ini file I've set to these same values:
post_max_size=64M
upload_max_filesize=64M

Please try to do the same, to see whether this is the reason why it works for me since it seems as we are doing everything else the same.

Regards,

Mihaela
#237146
  • Eddy.vh
  • Eddy.vh's Avatar Topic Author
  • Away
  • Gold Boarder
  • Gold Boarder
  • Posts: 207
  • Karma: 1
  • Thank you received: 23

Eddy.vh replied the topic: Upload HTML5

Hi Mihaela.

It does not work for me.
I have only one non-multiple loading field max. filesize = 150000.

I chose (voluntarily) an image of more than 150000 kb. The message indicates that the image is too heavy and disappears from the screen.

I now select an image of weight less than 150000 kb, it appears on the screen and is accepted.

I validate the form and check my FTP. Two files appear, the first one "refused" but nevertheless loaded to some kb and the following accepted, the first one being corrupted.

I did tests with Firefox and Chrome…

Best regards.
#237152
Attachments:
  • Posts: 2461
  • Karma: 86
  • Thank you received: 333

mihaela replied the topic: Upload HTML5

In that case, it turns out that after all, this isn't a temporary solution for this bug, unfortunately.

I'm can't tell why for me it is working and in your case no.

So the issue remains until it is fixed by developers.

Regards,

Mihaela
#237153
  • Eddy.vh
  • Eddy.vh's Avatar Topic Author
  • Away
  • Gold Boarder
  • Gold Boarder
  • Posts: 207
  • Karma: 1
  • Thank you received: 23

Eddy.vh replied the topic: Upload HTML5

Thank you anyway for your tests and your help.

Have a nice day (very hot)
#237155
  • Posts: 2461
  • Karma: 86
  • Thank you received: 333

mihaela replied the topic: Upload HTML5

I'm glad to help, but I'm sorry I didn't manage to resolve this.

Enjoy your day as well. :)

Regards,

Mihaela
#237163
  • Posts: 4
  • Thank you received: 1

ericssonukfso replied the topic: Upload HTML5

I have the same problem but needed a work around for a big project we've been working on for several months. The reason #237133 doesn't work is because the file uploaded is a corrupt partial file substantially smaller than the defined upload limit.

The code below should help, just be aware of a few things to consider:
  1. This code assumes that only 1 file attachment is required per upload field.
  2. Multiple upload fields are supported if needed.
  3. Only the last file selected by an upload field will be kept once the form has been submitted (validation rule below helps here).

Usage
  1. Add the php code below to your Begin Submit piece.
  2. Rename imageFile on line 3 to the name of your upload field.
  3. Duplicate line 3 for any additional upload fields and set the last parameter to match those respective field names.
// Add to Begin Submit Pieces in More Options dialog.

$this->execPieceByName('ff_InitLib');

html_5_upload_fix($this, 'imageFile');

/* 
 * Temp Fix for https://crosstec.org/en/forums/15-usage/126516-upload-html5.html
 * Remove partial file uploads from disk and data table that were over the 
 * maximum permitted file size and shouldn't have been uploaded.
*/
function html_5_upload_fix(&$form, $field_name){
    // get the name of the uploaded file element
    $field_array = ff_getSubmit($field_name, FF_ARRAY);
    
    // Ignore the successful/correctly sized file (first file in the array)
    if(count($field_array) > 1){
        foreach (array_slice($field_array, 1, count($field_array)) as $file) {
            $i = 0;
            foreach($form->savedata as $field){
                if($field[_FF_DATA_NAME] == $field_name && $field[_FF_DATA_VALUE] == $file){
                    // Remove unwanted field from data array
                    $form->savedata[$i][_FF_DATA_NAME] = "";
                    $form->savedata[$i][_FF_DATA_VALUE] = "";
                    // Delete the corrupt partial file
                    if (file_exists($file) && is_file($file)){
                        unlink($file);
                    }
                    continue 2;
                }
                $i++;
            }
        }
    }
}

Form 'File Upload' Field Settings
For ref, these are the advanced setting's I'm using that results in this bug:
  • Use HTML5 upload > Ticked
  • Use Flash upload (legacy) > Unticked
  • Allow multiple HTML5/Flash uploads > Unticked
  • HTML5/Flash max. filesize > 1000000
  • Upload directory > {mospath}/uploads/|
  • Timestamp > Ticked
  • Allowed file extensions > jpg,jpeg,gif,png
The rest are left as default.
I'm also using the bootstrap 2 theme engine if that makes any difference.

Explanation
The script first checks if the file upload field contains multiple files. If so, the first file in the array (last file selected by the upload) is skipped and the rest are iterated over. The script then removes the respective file paths from the save data array so their paths aren't written to the database. It then checks in the partial corrupt file exists, makes sure it's a file (we don't want to accidentally delete any folders), and then deletes the respective file.

Things to note:
  • If a user first selects an oversized file and then they subsequently leave the field blank (no file selected) this bug doesn't occur.
  • This issue only occurs if the user selected 1 or more oversized files before selecting one within the defined size limit.

2nd Bug
Users can still select multiple files within each upload field even though 'Allow multi HTML5/Flash uploads" is unticked! This means users may think they can attach multiple files to each upload field, unaware that only their last file will be kept.

To mitigate this bug you can create a new "Manage Scripts" validation piece with the following code:
  • Title > Validate single upload
  • Package > FF
  • Name > ff_validate_single_upload
  • Type > Element Validation
function ff_validate_single_upload(element, message){
    console.log("Start");
    if (message=='') message = "Please only attach 1 file to each field.\n";

    var valid = true;
    jQuery('.bfFlashFileQueueClass').each(function(i, obj) {
        //console.log("Num of children = " + jQuery(this).children().size());
        count = jQuery(this).children().size();
        if (count > 1) {
            return valid = false;
        }
    });

    if (valid == false){
        return message;
    }
    return '';
}

Usage
Within your form select your file upload field, select validation > library, then in the script drop down select FF::ff_validate_single_upload.

Explanation
The above validation script will loop through each of the file upload fields, if any of those fields contains more than 1 file it'll trigger the validation routines preventing the user moving on until they've reduced each file upload field to 1 or less files.

Issue:
The validation is not field specific searching every file upload field each time it's executed. As a result users will see the same validation error for however many file upload fields exist within the form. E.g. You have 3 file upload fields with this validation code, and only 1 field has 2 files attached, you'll see 3 duplicate validation messages stating to many files have been selected. I tried to work around this but without editing the BreezingForms framework I couldn't avoid this.

A bit long winded, but hopefully that should helps others.

KR,
Richard
#237224
The following user(s) said Thank You: MarioPuco
Moderators: ForumSupporttomeperica
Time to create page: 0.076 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here