## Aurigma Image Uploader 7.0.37

# Setting Limitations for Size and Number of Files

- Collapse All Sections
- See Also
- Language Filter ( all languages )

Image Uploader allows not only filtering files by type, or limiting images but also limiting size and count of files. It is extremely useful when you:

- want to allocate limited space on your server for users
- provide file hosting service, which does not allow uploading large files

## Restricting Number of Files for Upload

Note

Image Uploader Express restricts the maximum number of user-selected files to 100. See the Comparison of Image Uploader Editions topic for details.

To limit the maximum and minimum number of files allowed for the upload in a single upload session, use the Restrictions.MaxFileCount and Restrictions.MinFileCount properties respectively. If a user selects more files than specified by the Restrictions.MaxFileCount property, an error message (which can be customized using the Messages.MaxFileCountExceeded property) appears. If a user selects fewer files than the Restrictions.MinFileCount property value, the Upload button is disabled and files cannot be uploaded.

To remove both limitations, set Restrictions.MaxFileCount to 0 and Restrictions.MinFileCount to 1.

This example shows how to limit number of files from 3 to 10:

### ASP.NET

    <aur:Uploader ID="Uploader1" runat="server">
        <Restrictions  MinFileCount="3" MaxFileCount="10"/>
        <Messages MaxFileCountExceeded="You can add not more than 10 files."/>
    </aur:Uploader>

### PHP

    $uploader = new Uploader("Uploader1");
    $uploader->getRestrictions()->setMinFileCount(3);
    $uploader->getRestrictions()->setMaxFileCount(10);
    $uploader->getMessages()->setMaxFileCountExceeded("You can add not more than 10 files.");

### JavaScript

    var u = $au.uploader({
        id: 'Uploader1',
        restrictions: {minFileCount: 3, maxFileCount: 10},
        messages: {maxFileCountExceeded: 'You can add not more than 10 files.'}
    });

## Restricting Upload Size

To set a limit on a total size of files selected for the upload, Image Uploader exposes the Restrictions.MaxTotalFileSize property. When the sum of selected file sizes exceeds this value, an error specified with the Messages.MaxTotalFileSizeExceeded property is displayed.

If you do not need to restrict the total file size, set Restrictions.MaxTotalFileSize to 0.

This limitation is applied to sizes of original files only. It does not take into account sizes of files created by Image Uploader from original ones (downsized copies of images, associated icons, compressed ZIP files) because there is no way to know their sizes before upload process starts. Therefore, the amount of the actually uploaded bytes may noticeably differ from this value. So the Restrictions.MaxTotalFileSize property is useful when you upload original files without applying any client-side file transformations. Otherwise, if it is important to limit the POST request size, the only way is to configure maximum acceptable POST request length in the server settings.

This example shows how to limit upload size to 100 Mb:

### ASP.NET

    <aur:Uploader ID="Uploader1" runat="server">
        <Restrictions MaxTotalFileSize="104857600" />
        <Messages MaxTotalFileSizeExceeded="You are not allowed for uploading more than 100 MB."/>
    </aur:Uploader>

### PHP

    $uploader = new Uploader("Uploader1");
    $uploader->getRestrictions()->setMaxTotalFileSize(104857600);
    $uploader->getMessages()->setMaxTotalFileSizeExceeded("You are not allowed for uploading more than 100 MB.");

### JavaScript

    var u = $au.uploader({
        id: 'Uploader1',
        restrictions: {maxTotalFileSize: 104857600},
        messages: {maxTotalFileSizeExceeded: 'You are not allowed for uploading more than 100 MB.'},
    });

## Restricting Single File Size

Note

Image Uploader Express restricts the maximum size of each user-selected file to 100 Mb. Image Uploader Professional and Print restrict the maximum size of each user-selected file to 2 Gb. See the Comparison of Image Uploader Editions topic for details.

You can set a limitation not only for total size of the files selected for the upload, but also for a single file size. Both lower and upper limitations can be specified via the Restrictions.MinFileSize and Restrictions.MaxFileSize properties respectively. Files which are too large or too small cannot be selected, thus, they are invisible by default. Even if a user clicks Total files and tries to add such files to the upload list, Image Uploader displays an error message specified with the Messages.FileSizeTooSmall or Messages.MaxFileSizeExceeded property. Additionally, each inappropriate file is equipped with a tooltip containing the same error message text.

Both these properties should be set to 0 when no file size limitations are required.

In the following example files smaller than 200 Kb or larger than 2 Mb are denied:

### ASP.NET

    <aur:Uploader ID="Uploader1" runat="server">
        <Restrictions MinFileSize="204800" MaxFileSize="2097152" />
        <Messages FileSizeTooSmall="File is too small. You can add files not smaller than 200 KB."
            MaxFileSizeExceeded="File is too large. You can add files not larger than 2 MB."/>
    </aur:Uploader>

### PHP

    $uploader = new Uploader("Uploader1");
    $uploader->getRestrictions()->setMinFileSize(204800);
    $uploader->getRestrictions()->setMaxFileSize(2097152);
    $uploader->getMessages()->setFileSizeTooSmall("File is too small. You can add files not smaller than 200 KB.");
    $uploader->getMessages()->setMaxFileSizeExceeded("File is too large. You can add files not larger than 2 MB.");

### JavaScript

    var u = $au.uploader({
        id: 'Uploader1',
        restrictions: {minFileSize: 204800, maxFileSize: 2097152},
        messages: {fileSizeTooSmall: 'File is too small. You can add files not smaller than 200 KB.',
                   maxFileSizeExceeded: 'File is too large. You can add files not larger than 2 MB.'}
    });

Important

As limitations specified in Image Uploader are checked only on the client side, you should not interpret them as a reliable protection. A potential malicious user can bypass all these limitations (by emulating Image Uploader or modifying its parameters in a local copy of a page). That is why it is highly recommended to implement server-side verification of uploaded files in addition to Image Uploader file tests.

In other words, all limitation features discussed in this topic should be used solely for user's convenience. They should not be interpreted as a serious protection from malicious users.

## See Also

### Reference

- Restrictions Class
- Messages Class

### Manual

- Setting Limitations for Images
- Filtering Files by Names and Types

- MaxFileCount (ASP.NET)
- MaxFileCount (PHP)
- maxFileCount (JavaScript)

- MinFileCount (ASP.NET)
- MinFileCount (PHP)
- minFileCount (JavaScript)

- MaxFileCount (ASP.NET)
- MaxFileCount (PHP)
- maxFileCount (JavaScript)

- MaxFileCountExceeded (ASP.NET)
- MaxFileCountExceeded (PHP)
- maxFileCountExceeded (JavaScript)

- MinFileCount (ASP.NET)
- MinFileCount (PHP)
- minFileCount (JavaScript)

- MaxFileCount (ASP.NET)
- MaxFileCount (PHP)
- maxFileCount (JavaScript)

- MinFileCount (ASP.NET)
- MinFileCount (PHP)
- minFileCount (JavaScript)

- MaxTotalFileSize (ASP.NET)
- MaxTotalFileSize (PHP)
- maxTotalFileSize (JavaScript)

- MaxTotalFileSizeExceeded (ASP.NET)
- MaxTotalFileSizeExceeded (PHP)
- maxTotalFileSizeExceeded (JavaScript)

- MaxTotalFileSize (ASP.NET)
- MaxTotalFileSize (PHP)
- maxTotalFileSize (JavaScript)

- MaxTotalFileSize (ASP.NET)
- MaxTotalFileSize (PHP)
- maxTotalFileSize (JavaScript)

- MinFileSize (ASP.NET)
- MinFileSize (PHP)
- minFileSize (JavaScript)

- MaxFileSize (ASP.NET)
- MaxFileSize (PHP)
- maxFileSize (JavaScript)

- FileSizeTooSmall (ASP.NET)
- FileSizeTooSmall (PHP)
- fileSizeTooSmall (JavaScript)

- MaxFileSizeExceeded (ASP.NET)
- MaxFileSizeExceeded (PHP)
- maxFileSizeExceeded (JavaScript)

- Restrictions (ASP.NET)
- Restrictions (PHP)
- restrictions (JavaScript)

- Messages (ASP.NET)
- Messages (PHP)
- messages (JavaScript)