-2

I have this code:

     // 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;                
    }

from http://www.elvishsu.com/2014/01/start-your-own-mvc-framework-with-php.html#.V7lBVnUrLxs

Please can anyone tell me how to deal with file uploads in this situation I mean how should I deal with:

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

Thanks

tereško
  • 58,060
  • 25
  • 98
  • 150
gentle
  • 15
  • 7
  • 2
    That tutorial is terrifyingly bad. – tereško Aug 27 '16 at 21:45
  • I recommend you start with using a well known MVC framework first to understand the fundamentals, that tutorial is nothing but bad news. – Paradoxis Aug 27 '16 at 21:48
  • @Paradoxis I would disagree with expecting to learn MVC from a framework. I would recommend instead going through the materials listed here: http://stackoverflow.com/a/16356866/727208 **Frameworks do not implement MVC.** Your application code does .... or doesn't. – tereško Aug 27 '16 at 21:54

1 Answers1

0

This is what I resolve into:

// 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;                
    }

I put it here in case anyone is also trying to build MVC from that tutorial and find it difficult to upload Thanks everyone

gentle
  • 15
  • 7