To begin I worked with this solution but a wild error appear: Image Upload in a Custom Module
Here is my code :
function module_top_content_equipe_admin_form(){
$default = get_variable_value(variable_get('module_top_content_equipe_display', ''));
$default_image = variable_get('module_top_content_equipe_image', '');
$form['module_top_content_equipe_display'] = array(
'#type' => 'text_format',
'#name' => 'module_top_content_equipe_display',
'#title' => t('Content of the block'),
'#description' => t("Text to display"),
'#format' => 'filtered_html',
'#default_value' => $default,
);
$form['module_top_content_equipe_image'] = array(
'#type' => 'managed_file',
'#name' => 'module_top_content_equipe_image',
'#title' => t('Top Content page l equipe Image'),
'#description' => t("Image should be less than 400 pixels wide and in JPG format."),
'#default_value' => $default_image,
'#upload_location' => 'public://',
);
return system_settings_form($form);
}
function module_top_content_equipe_admin_form_submit($form, &$form_state){
if (isset($form_state['values']['module_top_content_equipe_image'])) {
$file = file_load($form_state['values']['module_top_content_equipe_image']);
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
}
}
and my error when I submit the form
Fatal error: Cannot unset string offsets in /includes/form.inc on line 2157
Thank you with advance