I've searched over the internet for half an hour but cannot find one.

I want to use the managed_file form api in D7 to allow use upload image file; more specifically, I think "#upload_validators" property may do the trick (if possible, to validate file extension before uploading; or at least, validate in the validation phase but not in the submit function). I've checked the image_example and file_example in the example modules, but cannot find a proper usage of it.

So I wonder if there's a proper tutorial on managed_file? Thanks a lot.

Update: I saw an example after doing a search on drupal directory from file.field.inc, and following the example, wrote code like this:

$form['file_upload'] = array(
  '#type'   => "managed_file",
  '#title'  => t("Upload"),
  '#descripion' => t("Only Image Files are allowed."),
  '#progress_indicator' => "bar",
  '#upload_location'    => "public://img/dish",
  "#upload_validators"  => array("file_validate_extensions" => "png gif jpg"),
);

This solved the problem.

Edit
Report