如果
应该发布的文件不是图像,JavaScript中是否有办法发布警报,或者如果没有选择文件,则返回true?
以下工作正常。在表单上提交 php 代码
<?php
$fileType = $_FILES['avatarfile']['type'];
if(isset($_POST['submit']) && (($_FILES['avatarfile']['type'] == "image/gif")
|| ($_FILES['avatarfile']['type'] == "image/jpeg")
|| ($_FILES['avatarfile']['type'] == "image/pjpeg") || ($_FILES['avatarfile']['type'] == "image/bmp") || ($_FILES['avatarfile']['type'] == "image/png") || $fileType == NULL))
{
$query="insert into ...)";
header('Location:something.php');
}
else {
echo "The file you tried to upload is not an image";
}
?>