HTML5捕获背面摄像头

发布于 2025-02-11 13:00:14 字数 1761 浏览 2 评论 0原文

我正在尝试从后面的摄像头捕获图像,代码按预期工作,手机在正面或背面打开,但是使用后面的摄像头,我得到了空的$ _files [“ filetoupload”]到PHP文件。如果我使用前置摄像头,则$ _files [“ filetoupload”] [“ tmp_name”]值将按预期提供给PHP文件。

<!DOCTYPE html>
<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
  Select image to upload:
   
  <input type="file" name="fileToUpload" id="fileToUpload"  accept="image/*" capture="environment">
  <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>

<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
echo $target_file.'<br>';
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
  $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  echo 'check '.$check;
  if($check !== false) {
    echo "File is an image - " . $check["mime"] .$_FILES["fileToUpload"]["tmp_name"];
    $uploadOk = 1;
  } else {
    echo "File is not an image.";
    $uploadOk = 0;
  }
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
  echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
  if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded.";
  } else {
    echo "Sorry, there was an error uploading your file.";
  }
}
?>

I am trying to capture an image from the back facing camera, the code works as expected the phone opens in either front or back, but using the back facing camera I get empty $_FILES["fileToUpload"]["tmp_name"] value passed to the php file. If I use the front facing camera a $_FILES["fileToUpload"]["tmp_name"] value is supplied to the php file as expected.

<!DOCTYPE html>
<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
  Select image to upload:
   
  <input type="file" name="fileToUpload" id="fileToUpload"  accept="image/*" capture="environment">
  <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>

<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
echo $target_file.'<br>';
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
  $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  echo 'check '.$check;
  if($check !== false) {
    echo "File is an image - " . $check["mime"] .$_FILES["fileToUpload"]["tmp_name"];
    $uploadOk = 1;
  } else {
    echo "File is not an image.";
    $uploadOk = 0;
  }
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
  echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
  if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded.";
  } else {
    echo "Sorry, there was an error uploading your file.";
  }
}
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合久必婚 2025-02-18 13:00:14

要回答我自己的问题max_file_size需要在php.ini文件中进行编辑以从默认的2M增加文件大小

To answer my own question max_file_size upload needed to be edited in the php.ini file to increase the file size from the default 2m

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文