1

I work on D7, and create form from custom modules. Create a field upload images by $form['#attributes']['enctype'] = 'multipart/form-data'; $form['image'] = array(

'#type' => 'file', '#title' => t('Upload picture'), '#description' => t('Select a picture of at least @dimensionspx and maximum @filesize.', array( '@dimensions' => '1000x1000', '@filesize' => format_size(file_upload_max_size()), )), 

);

Show form correct.

enter image description here

and submit form by hook_form_submit(); print $form_state, upload images not find. How to get values of upload image.

Write Also

$file = file_save_upload('image', array( 'file_validate_is_image' => array(), 'file_validate_image_resolution' => array('500x500', '100x100'), ), 'public://uploaded_images/', FILE_EXISTS_RENAME);

Not find of upload image.

2 Answers 2

1

Drupal makes a distinction between regular files and managed files. The first are only stored on the filesystem, the second are stored in the database (managed) as well.

If you use a manged file (type = 'managed_file') the $form_state will contain a file id (fid) of the newly stored image.

Also note that file_save_upload takes the file path as the first parameter, so 'image' means nothing there. And that you still have to store your image as a permanent file after file_save_upload():

$file = file_load($logo); $file->status = FILE_STATUS_PERMANENT; file_save($file); file_usage_add($file, 'your_module', 'using_entity_type', $entity_id); 
-2

The values are in $_FILES.

You shouldn't need to set the enctype of the form, Drupal will handle that for you automatically.

1
  • Weird that someone down-voted me, considering I answered the question that was asked. Commented Dec 23, 2016 at 12:45

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.