如何允许input type = file仅接受Safari中的图像文件

时间:2014-10-07 20:52:57

标签: javascript html angularjs safari

我有这个:

<input class="inline" id="imgInput" name='imgInput' type="file" ng-file-select="saveImage($files)" accept="image/*" data-ng-model="inputImage">

它适用于Mozilla和Chrome,但在Safari中我可以选择任何类型的文件。如何让输入只接受Safari中的图像文件?

1 个答案:

答案 0 :(得分:0)

这是我用来检查文件是否是图片的代码的一部分。

<?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");
}

?>