Take a photo in an App with Android smartphone [closed]

3 weeks ago 29
ARTICLE AD BOX

I'd like to make an php App with which you can take a photo and see the photo on your phone.

I wrote the code below which works properly on an iPad but doesn't work with an Android device.

The first one is a camera function which takes a photo and sends the image to upload.php

<?php function camera() { echo "<form enctype=\"multipart/form-data\" action=\"./upload.php\" method=\"POST\">"; echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"10000000\" />"; echo "<label class=\"menu_text\" for=\"frontcamera\">take photo:</label>"; echo "<input class=\"shutter_button\" type=\"file\" id=\"frontcamera\" name=\"imagefile\" capture=\"environment\" accept=\"image/*\" />"; echo "<input class=\"shutter_button\" type=\"submit\" value=\"send\" />"; echo "</form>"; } ?>

And the next one is upload.php

<?php if (isset($_FILES['imagefile']) && $_FILES['imagefile']['error'] === UPLOAD_ERR_OK) { $tmp_name = $_FILES['imagefile']['tmp_name']; $original_name = $_FILES['imagefile']['name']; $save_dir = './image/'; if (!file_exists($save_dir)) { mkdir($save_dir, 0777, true); } $destination = $save_dir . $original_name; if (move_uploaded_file($tmp_name, $destination)) { echo "file '$original_name' is uploaded successfully!"; } else { echo "failed"; } } else { echo "error"; } ?>

When I try to use this code with Android phone, I can take a photo as I want, but the photo is not saved in ./image/ directory whose permission is 777.

So I researched further, I found $_FILES['imagefile']['tmp_name'] is empty on Android.

On the other hand, when I use the same code with iPad, it works perfectly.

Can anyone give me a clue?

---

My environments are listed below

server : Ubuntu 22.04.4 LTS

Android : version 10

Chrome on Android : 142.0.7444.171

PHP : 8.3.9

Read Entire Article