## Aurigma Image Uploader Flash 1.0

# Configuring Restrictions and File Filters

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

This topic contains information on the application of various restrictions to the files that are uploading to your server. These restriction rules can be specified with the restrictions property of the imageUploaderFlash class.

Note

All the limitations specified with restrictions are checked client-side, so you should not interpret them as a reliable protection. A potentially malicious user can bypass all these limitations (by emulating Image Uploader Flash). That is why it is highly recommended to implement server-side verification of uploaded files in addition to restrictions properties.

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

## Configuring File Filter

When the user clicks the Add Files button a standard Open File dialog is shown. Files allowed for upload from client-side can be filtered using Files of type drop-down list. By default, no filter applied and Image Uploader Flash displays all files in the currently selected folder. If you want to add your own filter options use the fileFilters property of the restrictions class. This property accepts an array of filters each of which consists of the description string and files template. The description is displayed in the Files of type drop-down list and the template specifies a file mask applied onto the files. The order of these rules corresponds to the order in which they appear in the Files of type list.

The code sample below demonstrates how to set three filtering options, namely, Images, Documents, and All files.

### JavaScript

    var fu = $au.imageUploaderFlash({id: 'Uploader1'});

    fu.restrictions({
        fileFilters: [
            ['Images (*.jpg; *.jpeg; *.png; *.gif; *.bmp)', '*.jpg;*.jpeg;*.png;*.gif;*.bmp'],
            ['Documents (*.txt;*.rtf;*.pdf;*.doc;*.docx;*.xls;*.xlsx)', '*.txt;*.rtf;*.pdf;*.doc;*.docx;*.xls;*.xlsx'],
            ['All files (*.*)', '*.*']
        ]
    });

In ASP.NET control and PHP library the corresponded properties accept a JSON formatted string containing the array of filtering options (the same as you use to initialize the JavaScript property):

### ASP.NET

    <aur:ImageUploaderFlash ID="Uploader1" runat="server">
        <Restrictions FileFilters=
            "[['Images (*.jpg; *.jpeg; *.png; *.gif; *.bmp)', '*.jpg;*.jpeg;*.png;*.gif;*.bmp'],
              ['Documents (*.txt;*.rtf;*.pdf;*.doc;*.docx;*.xls;*.xlsx)', '*.txt;*.rtf;*.pdf;*.doc;*.docx;*.xls;*.xlsx'],
              ['All files (*.*)', '*.*']]"
        />
    </aur:ImageUploaderFlash>

### PHP

    $uploader = new ImageUploaderFlash();

    $uploader->getRestrictions()->setFileFilters(
        "[['Images (*.jpg; *.jpeg; *.png; *.gif; *.bmp)', '*.jpg;*.jpeg;*.png;*.gif;*.bmp'],
          ['Documents (*.txt;*.rtf;*.pdf;*.doc;*.docx;*.xls;*.xlsx)', '*.txt;*.rtf;*.pdf;*.doc;*.docx;*.xls;*.xlsx'],
          ['All files (*.*)', '*.*']]"
    );

## Specifying Restrictions

Image Uploader Flash allows restricting files not only by type, but also by file size, total number of selected for upload files, and image dimensions.

### Restricting Number of Files

To limit the minimum and maximum numbers of files allowed for the upload in a single upload session, use the minFileCount and maxFileCount properties respectively. If users add more files than specified by the maxFileCount property, they will get an error message (which can be customized using the messages.tooManyFilesError property). If a user adds fewer files than the minFileCount property value and clicks Send, an error message specified with the messages.tooFewFilesError property will be shown. To remove these limitations, set the maxFileCount property to 0 and minFileCount to 1.

### JavaScript

    var fu = $au.imageUploaderFlash({id: 'Uploader1'});

    fu.restrictions({minFileCount: 3, maxFileCount: 10});
    fu.messages({
        tooFewFilesError: 'You can add not less than 3 files.',
        tooManyFilesError: 'You can add not more than 10 files.'
    });

### ASP.NET

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

### PHP

    $uploader = new ImageUploaderFlash();

    $uploader->getRestrictions()->setMinFileCount(3);
    $uploader->getRestrictions()->setMaxFileCount(10);
    $uploader->getMessages()->setTooFewFilesError("You can add not less than 3 files.");
    $uploader->getMessages()->setTooManyFilesError("You can add not more than 10 files.");

### Restricting Upload Size

To set a limit on a total size of files added to the upload list, Image Uploader Flash exposes the maxTotalSize property. When the sum of file sizes exceeds this value, an error specified with the messages.totalFileSizeTooLargeError property is displayed. If you do not need to restrict the total file size, set maxTotalSize 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 Flash 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 actually uploaded bytes may noticeably differ from this value. So the maxTotalSize 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.

### JavaScript

    var fu = $au.imageUploaderFlash({id: 'Uploader1'});

    fu.restrictions({maxTotalSize: 104857600});
    fu.messages({totalFileSizeTooLargeError: 'You are not allowed for uploading more than 100 MB.'});

### ASP.NET

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

### PHP

    $uploader = new ImageUploaderFlash();

    $uploader->getRestrictions()->setMaxTotalSize(104857600);
    $uploader->getMessages()->setTotalFileSizeTooLargeError("You are not allowed for uploading more than 100 MB.");

### Restricting Single File Size

You can set a limitation not only for total size of files added to the upload list, but also for a single file size. Both minimum and maximum limits can be specified with the minFileSize and maxFileSize properties respectively. Files that are too large or too small cannot be added to upload list: error message specified with the messages.fileTooSmallError or messages.fileTooLargeError property is displayed. Both minFileSize and maxFileSize properties should be set to 0 when no file size limitations are required.

### JavaScript

    var fu = $au.imageUploaderFlash({id: 'Uploader1'});

    fu.restrictions({minFileSize: 204800, maxFileSize: 2097152});
    fu.messages({
        fileTooSmallError: 'You can add files not smaller than 200 KB.',
        fileTooLargeError: 'You can add files not larger than 2 MB.'
    });

### ASP.NET

    <aur:ImageUploaderFlash ID="Uploader1" runat="server">
        <Restrictions MinFileSize="204800" MaxFileSize="2097152" />
        <Messages FileTooSmallError="You can add files not smaller than 200 KB."
                  FileTooLargeError="You can add files not larger than 2 MB." />
    </aur:ImageUploaderFlash>

### PHP

    $uploader = new ImageUploaderFlash();

    $uploader->getRestrictions()->setMinFileSize(204800);
    $uploader->getRestrictions()->setMaxFileSize(2097152);
    $uploader->getMessages()->setFileTooSmallError("You can add files not smaller than 200 KB.");
    $uploader->getMessages()->setFileTooLargeError("You can add files not larger than 2 MB.");

### Restricting Image Dimensions

When you use Image Uploader Flash to upload images (rather than arbitrary files) to your web site, you may desire to limit dimensions of these images. To restrict dimensions the restrictions class exposes the following properties:

- minImageWidth and minImageHeight - specify minimum allowed image dimensions (in pixels).
- maxImageWidth and maxImageHeight - specify maximum allowed image dimensions (in pixels).

If one of these restrictions is exceeded, Image Uploader Flash will not allow adding "wrong" images to the upload list. Error message specified with the messages.imageHeightTooLargeError, messages.imageHeightTooSmallError, messages.imageWidthTooLargeError, or messages.imageWidthTooSmallError property will be displayed.

### JavaScript

    var fu = $au.imageUploaderFlash({id: 'Uploader1'});

    fu.restrictions({
        minImageWidth: 800, minImageHeight: 800,
        maxImageWidth: 1600, maxImageHeight: 1600
    });
    fu.messages({
        imageHeightTooLargeError: 'Image height should be smaller than 1600 pixels.',
        imageHeightTooSmallError: 'Image height should be larger than 800 pixels.',
        imageWidthTooLargeError: 'Image width should be smaller than 1600 pixels.',
        imageWidthTooSmallError: 'Image width should be larger than 800 pixels.'
    });

### ASP.NET

    <aur:ImageUploaderFlash ID="Uploader1" runat="server">
        <Restrictions MinImageWidth="800" MinImageHeight="800"
                      MaxImageWidth="1600" MaxImageHeight="1600" />
        <Messages ImageHeightTooLargeError="Image height should be smaller than 1600 pixels."
                  ImageHeightTooSmallError="Image height should be larger than 800 pixels."
                  ImageWidthTooLargeError="Image width should be smaller than 1600 pixels."
                  ImageWidthTooSmallError="Image width should be larger than 800 pixels." />
    </aur:ImageUploaderFlash>

### PHP

    $uploader = new ImageUploaderFlash();

    $uploader->getRestrictions()->setMinImageWidth(800);
    $uploader->getRestrictions()->setMinImageHeight(800);
    $uploader->getRestrictions()->setMaxImageWidth(1600);
    $uploader->getRestrictions()->setMaxImageHeight(1600);
    $uploader->getMessages()->setImageHeightTooLargeError("Image height should be smaller than 1600 pixels.");
    $uploader->getMessages()->setImageHeightTooSmallError("Image height should be larger than 800 pixels.");
    $uploader->getMessages()->setImageWidthTooLargeError("Image width should be smaller than 1600 pixels.");
    $uploader->getMessages()->setImageWidthTooSmallError("Image width should be larger than 800 pixels.");

## See Also

### Reference

- restrictions Class
- messages Class

- Restrictions (ASP.NET)
- Restrictions (PHP)
- restrictions (Java Script)

- ImageUploaderFlash (ASP.NET)
- ImageUploaderFlash (PHP)
- imageUploaderFlash (Java Script)

- Restrictions (ASP.NET)
- Restrictions (PHP)
- restrictions (Java Script)

- Restrictions (ASP.NET)
- Restrictions (PHP)
- restrictions (Java Script)

- FileFilters (ASP.NET)
- FileFilters (PHP)
- fileFilters (Java Script)

- Restrictions (ASP.NET)
- Restrictions (PHP)
- restrictions (Java Script)

- MinFileCount (ASP.NET)
- MinFileCount (PHP)
- minFileCount (Java Script)

- MaxFileCount (ASP.NET)
- MaxFileCount (PHP)
- maxFileCount (Java Script)

- MaxFileCount (ASP.NET)
- MaxFileCount (PHP)
- maxFileCount (Java Script)

- TooManyFilesError (ASP.NET)
- TooManyFilesError (PHP)
- tooManyFilesError (Java Script)

- MinFileCount (ASP.NET)
- MinFileCount (PHP)
- minFileCount (Java Script)

- TooFewFilesError (ASP.NET)
- TooFewFilesError (PHP)
- tooFewFilesError (Java Script)

- MaxFileCount (ASP.NET)
- MaxFileCount (PHP)
- maxFileCount (Java Script)

- MinFileCount (ASP.NET)
- MinFileCount (PHP)
- minFileCount (Java Script)

- MaxTotalSize (ASP.NET)
- MaxTotalSize (PHP)
- maxTotalSize (Java Script)

- TotalFileSizeTooLargeError (ASP.NET)
- TotalFileSizeTooLargeError (PHP)
- totalFileSizeTooLargeError (Java Script)

- MaxTotalSize (ASP.NET)
- MaxTotalSize (PHP)
- maxTotalSize (Java Script)

- MaxTotalSize (ASP.NET)
- MaxTotalSize (PHP)
- maxTotalSize (Java Script)

- MinFileSize (ASP.NET)
- MinFileSize (PHP)
- minFileSize (Java Script)

- MaxFileSize (ASP.NET)
- MaxFileSize (PHP)
- maxFileSize (Java Script)

- FileTooSmallError (ASP.NET)
- FileTooSmallError (PHP)
- fileTooSmallError (Java Script)

- FileTooLargeError (ASP.NET)
- FileTooLargeError (PHP)
- fileTooLargeError (Java Script)

- MinFileSize (ASP.NET)
- MinFileSize (PHP)
- minFileSize (Java Script)

- MaxFileSize (ASP.NET)
- MaxFileSize (PHP)
- maxFileSize (Java Script)

- Restrictions (ASP.NET)
- Restrictions (PHP)
- restrictions (Java Script)

- MinImageWidth (ASP.NET)
- MinImageWidth (PHP)
- minImageWidth (Java Script)

- MinImageHeight (ASP.NET)
- MinImageHeight (PHP)
- minImageHeight (Java Script)

- MaxImageWidth (ASP.NET)
- MaxImageWidth (PHP)
- maxImageWidth (Java Script)

- MaxImageHeight (ASP.NET)
- MaxImageHeight (PHP)
- maxImageHeight (Java Script)

- ImageHeightTooLargeError (ASP.NET)
- ImageHeightTooLargeError (PHP)
- imageHeightTooLargeError (Java Script)

- ImageHeightTooSmallError (ASP.NET)
- ImageHeightTooSmallError (PHP)
- imageHeightTooSmallError (Java Script)

- ImageWidthTooLargeError (ASP.NET)
- ImageWidthTooLargeError (PHP)
- imageWidthTooLargeError (Java Script)

- ImageWidthTooSmallError (ASP.NET)
- ImageWidthTooSmallError (PHP)
- imageWidthTooSmallError (Java Script)

- Restrictions (ASP.NET)
- Restrictions (PHP)
- restrictions (Java Script)

- Messages (ASP.NET)
- Messages (PHP)
- messages (Java Script)