Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

CGI::HtmlExtension#file_field

file_field(name = "", size = 20, maxlength = nil)

Generate an File Upload Input element as a string.

The attributes of the element can be specified as three arguments, name, size, and maxlength. maxlength is the maximum length of the file’s name, not of the file’s contents.

Alternatively, the attributes can be specified as a hash.

See multipart_form() for forms that include file uploads.

Example
file_field("name")
  # <INPUT TYPE="file" NAME="name" SIZE="20">

file_field("name", 40)
  # <INPUT TYPE="file" NAME="name" SIZE="40">

file_field("name", 40, 100)
  # <INPUT TYPE="file" NAME="name" SIZE="40" MAXLENGTH="100">

file_field("NAME" => "name", "SIZE" => 40)
  # <INPUT TYPE="file" NAME="name" SIZE="40">
See also #checkbox_group #form #checkbox #hidden also in 3.4 · 3.3 · 3.1 · 3.0