fileUpload

Type: Boolean String

Default: false

Sets URL path to the file upload script.

$R('#content', {
        fileUpload: '/myadmin/files/upload/'
});

The file will be transmitted in FILES array, for example, in PHP:

$_FILES['file']

By default, variable name is file, but this can be changed using the fileUploadParam setting.

File script must return a JSON string in following format in order for an file to be inserted into Redactor:

{
    filekey: {
        "url": "/files/myfile.txt",
        "name": "My file", // optional
         "id": "1"
    }
}

In PHP, such string can be created like this:

$files = [];
$files['filekey'] = [
    'url' => '/tmp/files/myfile.txt',
    'name' => 'My file', // optional
    'id' => 1
];

echo stripslashes(json_encode($files));

fileUploadParam

Type: String

Default: file

This setting allows to change default name ('file') for fileUpload option.

$R('#content', {
    fileUpload: '/myadmin/files/upload/',
    fileUploadParam: 'my-name'
});

In this example, fileUpload variable name will be my-name and it can be retrieved like this (in PHP):

$_FILES['my-name']

fileData

Type: Object Boolean

Default: false

This setting allows you to send POST params to your upload script.

$R('#content', {
        fileUpload: '/myadmin/files/upload/',
        fileData: {
            id: 10,
        elements: '#my-input-1, #my-input-2, #my-form'
    }
});

The example above shows how to send POST params with uploading a file. The data object has key=value params, including values in the input and form fields if the additional object has key elements with field and form selectors.

The values of the input and form fields are appended as values: field-name: value.

fileAttachment

Type: Boolean String

Default: false

This setting allows you to upload files as attachment of Redactor. Just set the selector ID of the attachment target and files will be inserted it in after the uploading.

// textarea
<textarea id="content"></textarea>

// attachment target
<div id="file-target"></div>

// call Redactor
$R('#content', {
        fileUpload: '/myadmin/files/upload/',
        fileAttachment: '#file-target'
});