2

我正在尝试在 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...

多谢你们

4

1 回答 1

0

查看此错误:

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
于 2012-07-19T12:14:26.340 回答