仅发布图像文件或允许发布无文件

时间:2012-06-27 23:13:38

标签: php javascript html

如果应该发布的文件不是图像,如果没有选择文件,javascript是否有办法发布警告?

1 个答案:

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