如何上传文件MVC php

如何上传文件MVC php,php,Php,我有以下代码: // assign params by methods switch($method){ case "GET": // view // we need to remove _route in the $_GET params unset($_GET['_route']); // merege the params $this->para

我有以下代码:

     // assign params by methods  
       switch($method){
        case "GET": // view
            // we need to remove _route in the $_GET params
            unset($_GET['_route']);
            // merege the params
            $this->params_ = array_merge($this->params_, $_GET);               
        break;
        case "POST": // create
        case "PUT":  // update
        case "DELETE": // delete
        {
            // ignore the file upload
            if(!array_key_exists('HTTP_X_FILE_NAME',$_SERVER))
            {
                if($method == "POST"){
                    $this->params_ = array_merge($this->params_,      $_POST); 
                }else{           
                    // temp params 
                    $p = array();
                    // the request payload
                    $content = file_get_contents("php://input");
                    // parse the content string to check we have [data] field or not
                    parse_str($content, $p);
                    // if we have data field
                    $p = json_decode($content, true);
                    // merge the data to existing params
                    $this->params_ = array_merge($this->params_, $p);
                }   
            }          
        }
        break;                
    }

请告诉我在这种情况下如何处理文件上传 我的意思是我应该如何处理:

 if(array_key_exists('HTTP_X_FILE_NAME',$_SERVER))

谢谢

这就是我的决心:

// assign params by methods  
    switch($method){
        case "GET": // view
            // we need to remove _route in the $_GET params
            unset($_GET['_route']);
            // merege the params
            $this->params_ = array_merge($this->params_, $_GET);               
        break;
        case "POST": // create
        case "PUT":  // update
        case "DELETE": // delete
        {

                if($method == "POST" && isset($_FILES)){
                    if (!empty($_FILES))
                    {
                        $this->params_ = array_merge($this->params_, $_POST);
                        $this->params_ = array_merge($this->params_, $_FILES);                            
                    }else{
                        $this->params_ = array_merge($this->params_, $_POST); 
                    }
                }else{           
                    // temp params 
                    $p = array();
                    // the request payload
                    $content = file_get_contents("php://input");
                    // parse the content string to check we have [data] field or not
                    parse_str($content, $p);
                    // if we have data field
                    $p = json_decode($content, true);
                    // merge the data to existing params
                    $this->params_ = array_merge($this->params_, $p);
                }   

        }
        break;                
    }
我把它放在这里,以防有人也试图从该教程中构建MVC,并且发现很难上传
谢谢大家

那篇教程糟透了。我建议你首先使用一个著名的MVC框架来理解基本原理,那篇教程只不过是个坏消息。@Paradoxis我不同意从一个框架学习MVC。我建议大家阅读下面列出的材料:框架不实现MVC。您的应用程序代码是。。。。或者没有。