简体   繁体   English

HTML5 捕捉后置摄像头

[英]HTML5 capture back facing camera

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.我正在尝试从后置摄像头捕获图像,代码按预期工作,手机在正面或背面打开,但使用后置摄像头我得到空的 $_FILES["fileToUpload"]["tmp_name"] 值传递到 php 文件。 If I use the front facing camera a $_FILES["fileToUpload"]["tmp_name"] value is supplied to the php file as expected.如果我使用前置摄像头,则会按预期将 $_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."; } } ?>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM