Forums

Multiple File Upload - File Validation (Allowed types and file sizes)

gatekeepa123 30 Jan, 2016
Hello everybody,

I've a form where the user is able to decide how much file(s) he wants to upload; he should also be able to send a form without any file: the file field isnt required..

I followed the tutorial found here to archive this: http://www.chronoengine.com/faqs/70-cfv5/5245-how-can-i-use-the-multiplier-in-cfv5.html

I'm now trying to validate the files, the user uploads. I dont want the user to upload files bigger than 5 mb and I only want him to upload files with the extensions jpg-png-gif-pdf-zip-rar.

Here is what I did so far:

[attachment=0]designer_multiplier_overview.png[/attachment]

[attachment=1]setup_overview.png[/attachment]

[attachment=2]setup_files_upload_1.png[/attachment]

[attachment=3]setup_files_upload_2.png[/attachment]

If I now test the form, I get the following results:

1. If I upload a file that is not allowed, I get the correct error message for wrong file type (Perfect!)

2. If I upload one file that is allowed and one that is not allowed, I get the correct error message for wrong file type (Good!)

3. If I upload two files that are allowed, an E-Mail with both files attached is sent (Perfect!)

4. If I upload a file that is not allowed and too big, an error message is show: This file is too big! (Good, better: This file is too big and the file type is not allowed)

5. If I upload a file that is allowed, but bigger than 5 MB an empty E-Mail is sent without the attachment and no error message (file is too big!) is shown (Problem!)

6. The same happens, when I upload one file that is allowed and one file that is too big

I'm afraid the answer to this is very complex because of the multiplier option. Or is is simple and I'm just missing something?🙂

As always: Thank you very much in advance.

Best Regards,
Marc
GreyHead 31 Jan, 2016
Hi Marc,

This does get complicated with the multiplier - here I'm wondering if the big files are ever getting to ChronoForms. What is the max_file_size setting in php.ini?

If you add a Custom Code action with this code do you see the files?
<?php
echo'<div>$_FILES: '.print_r($_FILES, true).'</div>';
?>

Bob
gatekeepa123 31 Jan, 2016
Hey GreyHead,

thank you for the reply. upload_max_filesize is 12 MB.

I cant see the file, if I upload a file with an allowed file extension that is too big. It only shows: $_FILES: Array ( )

Full Debug:

$_FILES: Array ( )
Vielen Dank für Ihre Nachricht.
Data Array
Array
(
    [chronoform] => Immobilien
    [event] => submit
    [ip_address] => 88.152.14.55
)
Array
(
)
Errors
Array
(
)
Debug Info
Array
(
    [11] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:marc.grube@pixeltopf.com
                    [2] => Subject:Angebotsanfrage auf klarmann-immobilien.de
                    [3] => From name:Klarmann Immobilien Formmailer
                    [4] => From email:formmailer@klarmann-immobilien.de
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:
                    [8] => Reply email:
                    [9] => Attachments:
                    [10] => Array
                        (
                        )

                    [11] => Body:
Sehr geehrte Damen und Herren,<br/><br/>

es ist eine neue Angebotsanfrage eingegangen.<br/><br/>


<table>
<tr><td>Name:</td><td></td></tr>
<tr><td>E-Mail:</td><td></td></tr>
<tr><td>Telefonnummer:</td><td></td></tr>
<tr><td>Adresse:</td><td></td></tr>
</table>

<br/><br/>

Ich bin<br/>
<br/>

<br/><br/>

Objektart:<br/>
<br/>

<br/><br/>

<table>
<tr><td>Nachricht:</td><td></td></tr>
</table>


<br /><br />IP: 88.152.14.55
                )

        )

)
$_FILES: Array ( )
GreyHead 31 Jan, 2016
Hi Marc,

Puzzled . . .

Please double check the max_file_size on the Site Admin | System Info | PHP Info page.

If the file has been uploaded then the info should be in the $_FILES array

Bob
gatekeepa123 01 Feb, 2016
Hey Greyhead,

phpinfo.php shows upload_max_filesize is 12 MB. Admin / System / PHP Information shows upload_max_filesize upload_max_filesize 12 M and post_max_size 8 M. If I upload a file with the correct file size the info is shown:

$_FILES: Array ( [file] => Array ( [name] => Array ( [0] => Informationsbroschuere.pdf ) [type] => Array ( [0] => application/pdf ) [tmp_name] => Array ( [0] => /tmp/php5MiZqV ) [error] => Array ( [0] => 0 ) [size] => Array ( [0] => 1450054 ) ) )
GreyHead 01 Feb, 2016
Hi Marc,

Thank you. What I don't understand at the moment is why the $_FILES array doesn't include the 'oversize' files if they are under the max_file_size limit I think that they should show up there.

Bob
This topic is locked and no more replies can be posted.