使用MVC PHP保存图像


Saving image with MVC PHP

我试图在MVC系统上处理表单,但无法将图像保存在服务器上。我得到的错误是:

Warning: move_uploaded_file(/xcomplete/xtyre/public/images/products/brunofitasHD.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/gbengmux/public_html/xcomplete/xtyre/models/insert_model.php on line 120
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpFHXzmh' to '/xcomplete/xtyre/public/images/products/brunofitasHD.jpg' in /home/gbengmux/public_html/xcomplete/xtyre/models/insert_model.php on line 120

这是我的代码

由视图类显示的表单:

<form action="<?php echo DOC_ROOT;?>/insert" class="mainForm" id="tyreForm"    method="POST" enctype="multipart/form-data">
<!-- Dropdowns and selects -->
        <fieldset>
            <div class="widget">
                //OTHER FIELDS HERE...
                <div class="rowElem">
                    <label>Photo:</label> 
                    <div class="formRight">
                        <input type="file" name="file" id="file" class="fileInput"  />
                         <input id="submitButton" type="button" value="Insert" class="greyishBtn submitForm" />
                    </div>
                    <div class="fix"></div> 
                </div>
            </div>     
    </fieldset>
</form>

控制器:@/插入

    class Insert extends XController{
             public function __construct(){
            parent::__construct();
            if(XSession::get(APP_NAME.'/loggedIn')){
                $this->view->pageTitle = "Insert Tyres";
                $this->loadModel("insert_model");
            }
            else{
                header('location: '.DOC_ROOT.DS.'login');
            }

        }
         //THIS FUNCTION IS CALLED AFTER THE CONSTRUCTOR
        public function index(){
            //CALLING THE FUNCTION TO PROCESS FORM
            $this->model->run();
            //GETTING MODEL VARS
            $this->view->pars = $this->model->getPars();
            //LOADING MODULES
            $this->loadModule("mod_top_nav");
            $this->runModules();
            //RENDER VIEW   
            $this->view->render("insert");
        }
...
}

处理表单的模型:

class Insert_Model extends XModel{
function __construct(){
    parent::__construct();
    $this->xdb->open();
    $this->getBrands();
    $this->getWidth();
    $this->getDiameter();
    $this->getRatio();
    $this->getLoadIndex();
}
function run(){
    //OTHER POST 's...

            //processing data

            if (($_FILES["file"]["type"] == "image/gif")
            || ($_FILES["file"]["type"] == "image/jpeg")
            || ($_FILES["file"]["type"] == "image/png")
            || ($_FILES["file"]["type"] == "image/pjpeg"))
            {
                if($_FILES["file"]["size"] < 100000){
                    if ($_FILES["file"]["error"] > 0){
                        array_push($this->pars['error'], 'File Error');
                        return false;
                    }
                    else{
                        //THE ERROR IS HERE
                        if(move_uploaded_file($_FILES["file"]["tmp_name"],
                                   DOC_ROOT."/public/images/products/" . $_FILES["file"]["name"])){
                                return true;
                        }
                        else{
                            array_push($this->pars['error'], 'Could not save file');
                        }
                    }
                }
                else{
                    array_push($this->pars['error'], 'File is too big');
                    return false;
                }
            }
            else{
                array_push($this->pars['error'], 'Invalid File');
                return false;
            }

            //PROCESS DATA ETC...

谢谢各位

查看此错误:

Warning: move_uploaded_file() [function.move-uploaded-file]:
Unable to move '/tmp/phpFHXzmh' 
to 
'/xcomplete/xtyre/public/images/products/brunofitasHD.jpg' 
in /home/gbengmux/public_html/xcomplete/xtyre/models/insert_model.php on line 120

路径似乎是错误的IE从一开始就缺少了一些东西。。它不应该尝试将文件转换为这个吗?

/home/gbengmux/public_html/xcomplete/xtyre/public/images/products/brunofitasHD.jpg