file-uploadsample

Display a file upload field that displays a preview of the file uploaded.

Option Details & Parameters

Typefile

Returnsstring

Version1.10

Can be placed in: Admin Panels , Admin Tabs , Meta Boxes , Theme Customizer

Parameter Type Description
name string The name of the option, for display purposes only.
id string A unique ID for this option. This ID will be used to get the value for this option.
desc string The description to display together with this option.
default string (Optional) The default value for this option.
label string (Optional) The label of the file upload preview.
livepreview string (Optional) jQuery code that updates something in your site in the live preview. Only used when the option is placed in a theme customizer section. Refer to Livepreview for more information on this parameter.
css string (Optional) CSS rules to be used with this option. Only used when the option is placed in an admin page / panel or a theme customizer section. Refer to Generate CSS Automatically for your options for more information on this parameter.
placeholder string (Optional) The text to display inside the field when the field is empty.

Return Value

The file upload option returns an attachment ID of the selected file.

The WordPress function get_attached_file() can be used to get the URL and details on the selected file. More info in the Codex: https://codex.wordpress.org/Function_Reference/get_attached_file

Examples

Creating a file upload option:

$panel->createOption( array(
'name' => 'My File Upload Option',
'id' => 'my_file_upload_option',
'type' => 'file',
'desc' => 'Upload your file'
) );