File upload zendframework2上传文件

File upload zendframework2上传文件,file-upload,zend-framework2,File Upload,Zend Framework2,我有一个表单,有多个file类型的字段。foto1,foto2,foto3,foto4,foto5,foto6 只需要第一个字段。使用下面看到的代码上载文件 检查表单有效性后,在正常控制器操作内调用此方法 private function uploadFile($file,$methodName,$idCategoriaEvento,&$categoriaEventoEntity){ $obj = new \stdClass(); try{ //unset

我有一个表单,有多个file类型的字段。foto1,foto2,foto3,foto4,foto5,foto6 只需要第一个字段。使用下面看到的代码上载文件

检查表单有效性后,在正常控制器操作内调用此方法

private function uploadFile($file,$methodName,$idCategoriaEvento,&$categoriaEventoEntity){
    $obj = new \stdClass();
    try{
        //unset($_FILES['fotoGrande'],$_FILES['fotoBanner'],$_FILES['foto1'],$_FILES['foto2'],$_FILES['foto3'],$_FILES['foto4'],$_FILES['foto5'],$_FILES['foto6']);
        if(!empty($file['tmp_name'])){
            $getBasePath = new Getbasepath($this);
            $this->getCurConfig();
            $path_origine = $file['name'];
            $ext = pathinfo($path_origine, PATHINFO_EXTENSION);
            $file_name = $file['tmp_name'];

            $new_file = $getBasePath->getPath().$this->config['ristotram']['categoria_foto_path']. $idCategoriaEvento . "/" . $path_origine;

            $upload_obj = new \Zend\File\Transfer\Adapter\Http();

            $upload_obj->addFilter('File\Rename',array(
                'source' => $path_origine,
                'target' => $new_file,
                'overwrite' => true
            ));


            if($upload_obj->receive()) {
                //$categoriaEventoEntity->$methodName($path_origine);
                $obj->s = true;
                $obj->i = "";
            }else{
                $obj->s = false;
                $obj->i = implode("<br />",$upload_obj->getErrors());
            }
        }else{
            $obj->s = true;
            $obj->i = "";
        }
    }catch(\Exception $e){
        $obj->s = false;
        $obj->i = $upload_obj->getErrors();
    }
    return $obj;
}
文件未移动到目标,但未显示任何错误

确定代码错误

private function uploadFile($file,$methodName,$idCategoriaEvento,&$categoriaEventoEntity){
    $obj = new \stdClass();
    try{
        if(!empty($file['tmp_name'])){
            $this->getCurConfig();
            $file_name = $file['name'];
            $file_temp_name = $file['tmp_name'];
            $new_file = $this->plgBasePath->getPath().$this->config['ristotram']['categoria_foto_path']. $idCategoriaEvento . "/" . $file_name;
            $upload_obj = new Http();
            $upload_obj->addFilter('File\Rename',array(
                'source' => $file_temp_name,
                'target' => $new_file,
                'overwrite' => true
            ));
            if($upload_obj->receive()) {
                $categoriaEventoEntity->$methodName($file_name);
                $obj->s = true;
                $obj->i = "";
            }else{
                $obj->s = false;
                $obj->i = implode("<br />",$upload_obj->getErrors());
            }
        }else{
            $obj->s = true;
            $obj->i = "";
        }
    }catch(\Exception $e){
        $obj->s = false;
        $obj->i = $upload_obj->getErrors();
    }
    return $obj;
}
private function uploadFile($file,$methodName,$idCategoriaEvento,&$categoriaEventoEntity){
    $obj = new \stdClass();
    try{
        if(!empty($file['tmp_name'])){
            $this->getCurConfig();
            $file_name = $file['name'];
            $file_temp_name = $file['tmp_name'];
            $new_file = $this->plgBasePath->getPath().$this->config['ristotram']['categoria_foto_path']. $idCategoriaEvento . "/" . $file_name;
            $upload_obj = new Http();
            $upload_obj->addFilter('File\Rename',array(
                'source' => $file_temp_name,
                'target' => $new_file,
                'overwrite' => true
            ));
            if($upload_obj->receive()) {
                $categoriaEventoEntity->$methodName($file_name);
                $obj->s = true;
                $obj->i = "";
            }else{
                $obj->s = false;
                $obj->i = implode("<br />",$upload_obj->getErrors());
            }
        }else{
            $obj->s = true;
            $obj->i = "";
        }
    }catch(\Exception $e){
        $obj->s = false;
        $obj->i = $upload_obj->getErrors();
    }
    return $obj;
}