<分区>
所以基本上如何过滤窗口弹出窗口以仅在我单击输入类型文件时显示图像文件
<input type="file" />
感谢任何帮助,我尝试为此找到解决方案
谢谢
<分区>
所以基本上如何过滤窗口弹出窗口以仅在我单击输入类型文件时显示图像文件
<input type="file" />
感谢任何帮助,我尝试为此找到解决方案
谢谢
最佳答案
您可以使用它,但它不适用于所有浏览器:
<input type="file" accept="image/*">
在 Chrome 中,您甚至可以指定允许的格式:
<input type="file" accept="image/x-png, image/gif, image/jpeg" />
如果要限制图片类型you can still use JavaScript to validate it在客户端。
当然你也应该用 PHP 在服务器端检查它:
//defining the allowed extensions and types for our system.
$allowedMimes = array('image/gif', 'image/jpeg', 'image/jpg', 'image/png', 'image/bmp', 'image/wbmp');
$allowedExtensions = array('jpg', 'gif', 'jpeg', 'png', 'bmp', 'wbmp');
$extension = end(explode('.',$imgFile));
//is the extension allowed?
if(in_array($extension, $allowedExtensions)){
//getting the mime type (it can be different from the extension) Be careful!
$imgInfo = getimagesize('yourPath/'.$imgFile);
$type = strtolower($imgInfo['mime']);
//checking the mime type
if(!in_array($type, $allowedMimes)){
// is an allowed image type
}
}
关于php - 在输入类型文件浏览窗口中只显示图像文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16832255/