Creating a File-Upload inside an Admin Box

This is a special type of field that lets administrators upload a file - or multiple files - from their computers.

When the file is uploaded, the administrator will see the file's name and extension (and width and height for images), but a string which can be used to identify the file will be stored in the field's value.

If you allow an administrator to upload multiple files using the multi property, their paths will appear in a comma-separated list.

Accepting files from Dropbox 

If the site has an API key from administrators can also choose files from their Dropbox accounts.

Note that the parameters for accepting files from Dropbox differ slightly in syntax to the parameters for uploading files in a browser, so you will need to set both the accept and extensions properties even though they contain the same information.

Handling the uploaded files

To handle the file in your validateAdminBox() and saveAdminBox() methods you will need to know where it has been stored on the server.

You can use the getPathOfUploadedFileInCacheDir() function to find this, by passing the value of the field from the Admin Box into the function to receive the location of the file on the server.

If you allow multiple uploads, the value of the field will contain a comma-separated list. You must explode() the value and loop through the resulting array first, as the getPathOfUploadedFileInCacheDir() function only works with one file at a time.

Displaying an existing file

If you have previously uploaded a file and saved it into the database, but still want to display it in the Admin Box, you can also put the file's id from the files table in this field's value.

The administrator will see the file's name and extension (and width and height for images), in the same way as if they had just uploaded it.

Reference for upload: