如果应该发布的文件不是图像或,如果没有选择文件,javascript是否有办法发布警告?
答案 0 :(得分:1)
以下工作正常。 在表单上提交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";
}
?>