Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML File Upload Doesn't Show Gallery on Android

I'd like my PHP app to accept a photo chosen from a mobile user's gallery. I'm testing on Android 4.4.4 using Chrome. This is my form:

<form enctype="multipart/form-data" action="index.php" method="POST">
  <input type="hidden" name="MAX_FILE_SIZE" value="20000000" />
  <input type="submit" value="Add" />
</form>

I've tried three different type="file" inputs and none of them give me the Gallery as an option:

  <input name="userfile" type="file" />

Options: Camera, Camcorder, Sound Recorder and Documents

  <input name="userfile" type="file" accept="images/*" />

Options: Camera and Documents

  <input name="userfile" type="file" accept="images/*" capture />

Goes straight into Camera.

Is there some straight-forward way to get Gallery to come up as an option or do I have do some round-about thing using JavaScript? Thanks for your answers.

like image 766
Jared Avatar asked Jun 28 '14 21:06

Jared


People also ask

How does HTML input type file work?

The input element, having the "file" value in its type attribute, represents a control to select a list of one or more files to be uploaded to the server. When the form is submitted, the selected files are uploaded to the server, along with their name and type.

How do you provide file upload option in HTML?

The <input type="file"> defines a file-select field and a "Browse" button for file uploads. To define a file-select field that allows multiple files to be selected, add the multiple attribute.


2 Answers

Try to use <input name="userfile" type="file" accept="image/*" />

instead of <input name="userfile" type="file" accept="images/*" />.

It works for me.

like image 159
Szmulik Avatar answered Sep 21 '22 04:09

Szmulik


Turns out this is a known bug in Android >= 4.4. My code works as expected in iOS.

like image 26
Jared Avatar answered Sep 22 '22 04:09

Jared