[英]How to allow input type=file to accept only images files in Safari
I have this: 我有这个:
<input class="inline" id="imgInput" name='imgInput' type="file" ng-file-select="saveImage($files)" accept="image/*" data-ng-model="inputImage">
It works in Mozilla and Chrome, but in Safari I can choose any kind of file. 它可以在Mozilla和Chrome中运行,但是在Safari中,我可以选择任何类型的文件。 How can I get the input to accept only image files in Safari?
如何获取输入以仅接受Safari中的图像文件?
This is a part of a code I use to check if file is a picture. 这是我用来检查文件是否为图片的代码的一部分。
<?php
if($_FILES['picture'] == '' OR empty($_FILES['picture']))
{
header("Location: picture.php?error=file");
}
elseif ($_FILES['picture']['error'] > 0)
{
if($_FILES['picture']['error'] == UPLOAD_ERR_NO_FILE)
{ header("Location: picture.php?error=file");}
elseif($_FILES['picture']['error'] == UPLOAD_ERR_INI_SIZE)
{ header("Location: picture.php?error=size");}
elseif($_FILES['picture']['error'] == UPLOAD_ERR_FORM_SIZE)
{ header("Location: picture.php?error=size");}
elseif($_FILES['picture']['error'] == UPLOAD_ERR_PARTIAL)
{ header("Location: picture.php?error=partial");}
else {
header("Location: picture.php?error=file");
}
}
$imageSize = getimagesize($_FILES['picture']['tmp_name']);
if($imageSize['mime'] == 'image/jpeg' OR $imageSize['mime'] == 'image/png' OR $imageSize['mime'] == 'image/gif')
{
$validExtensions = array('jpg','jpeg','gif','png');
$extension = strtolower(substr(strrchr($_FILES['picture']['name'], '.'),1));
if (!in_array($extension,$validExtensions))
{ header("Location: picture.php?error=extension");}
if ($_FILES['picture']['size'] > 5242880)
{ header("Location: picture.php?error=size");}
if ($imageSize[0] > 5000 OR $imageSize[1] > 5000)
{ header("Location: picture.php?error=size");}
//DO OTHER THINGS
}
else
{
header("Location: picture.php?error=type");
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.