PHP文件上传不更新备份数据库或上传文件


PHP File Upload not updaing database or uploading file

我一直在努力解决这个问题,我想做的是

  • 检查图像文本框是否为空
  • 查看文件是jpg还是pjpeg,如果不是,则返回无效图像
  • 看看是否有错误
  • 如果出现错误,显示错误如果不上传文件,则更新数据库

这是我的案例:

case"updatesubmit":
    if ($_FILES['image']['error'] === UPLOAD_ERR_OK) {
        if (($_FILES["image"]["type"] == "image/jpeg") || ($_FILES["image"]["type"] == "image/pjpeg")){
            if ($_FILES["image"]["error"] > 0){
                echo $_FILES["image"]["error"];
            }else{
                move_uploaded_file($_FILES["image"]["tmp_name"],
                "../upload/CV_1_" . date("Ymd") . $_FILES["image"]["name"]);    
                $class->update($id, $text, $image);
                echo "<div style='padding-left:50px'><strong>Updated!</strong></div>";
            }
        }else{
            echo "<div style='padding-left:50px'><strong>Invalid Image!</strong></div>";
        }
    }else{
        $class->updateWithoutImage($id, $text);
        echo "<div style='padding-left:50px'><strong>Updated!</strong></div>";
    }
        $array = $class->view();
        include("view/CV/view_display.html");
    break;

如果有人能给我指明正确的方向,那就太棒了!!!

您可以通过以下方式编辑代码:

list($width, $height, $type, $attr) = getimagesize($_FILES['image']['tmp_name']);
if($type!=2){ // SO IS NOT JPG
//ERROR
}