我想在检查图像大小,宽度和高度后上传图像,但我的脚本有错误。
代码:
<?php
include('dbcon.php');
$name=$_POST["name"];
$tel=$_POST["tel"];
//upload file syntax begining
$fileField=$_FILES["fileField"]["name"];
if($_FILES["fileField"]["size"] >= 50000) {
echo "bigfile";
}
elseif {
$fileField = @getimagesize($_FILES["fileField"]["tmp_name"]);
($fileField === FALSE || !($fileField[2] == IMAGETYPE_GIF || $fileField[2] == IMAGETYPE_JPEG || $fileField[2] == IMAGETYPE_PNG));
echo "Only Allow jpeg,PNG,Gif";
{
else{
move_uploaded_file($_FILES["fileField"]["tmp_name"],"upload/".$_FILES["fileField"]["name"]);
//upload file syntax ending
$sql="insert into imgtb(name,tel,image)values('$name','$tel','$fileField')";
$result=mysql_query($sql);
}
?>
有人请帮助修复错误!
答案 0 :(得分:1)
将您的代码更改为以下内容:
<?php
include('dbcon.php');
$name = $_POST["name"];
$tel = $_POST["tel"];
$fileField = $_FILES["fileField"]["name"];
if($_FILES["fileField"]["size"] >= 50000) {
echo "big image";
} else {
$fileField = @getimagesize($_FILES["fileField"]["tmp_name"]);
if ($fileField === FALSE || !($fileField[2] == IMAGETYPE_GIF || $fileField[2] == IMAGETYPE_JPEG || $fileField[2] == IMAGETYPE_PNG)) {
echo "Only Allow jpeg,PNG,Gif";
} else {
move_uploaded_file($_FILES["fileField"]["tmp_name"],"upload/".$_FILES["fileField"]["name"]);
$sql="insert into imgtb(name,tel,image)values('$name','$tel','$fileField')";
$result=mysql_query($sql);
}
}
?>
注意:您有很多语法错误。在插入DB之前,先转义所有变量。