简体   繁体   English

PHP文件上传未更新数据库或文件上传

[英]PHP File Upload not updaing database or uploading file

I have been banging my head against the wall trying to figure out this issue, what I am trying to do is 我一直在撞墙,试图找出这个问题,我想做的是

  • Check to see if the image textbox is blank or not 检查图像文本框是否为空白
  • See if the file is a jpg or pjpeg, if not return invalid image 查看文件是jpg还是pjpeg,如果没有返回无效图像
  • see if there are any errors 看看是否有任何错误
  • If an error, display error if not upload the file then update database... 如果有错误,则显示错误,如果不上传文件则更新数据库...

Here is my case: 这是我的情况:

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;

If anyone can point me in the right direction, that would be awesome!!! 如果有人能指出我正确的方向,那就太好了!!!

you could edit your code in this way: 您可以通过以下方式编辑代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM