Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter上载图像不工作_Php_File Upload_Codeigniter 3_Image Upload - Fatal编程技术网

Php Codeigniter上载图像不工作

Php Codeigniter上载图像不工作,php,file-upload,codeigniter-3,image-upload,Php,File Upload,Codeigniter 3,Image Upload,控制器 这部分连接到我的数据库 看法 编程语言:PHP Codeigniter 服务器:XAMPP 我是初学者 问题:如何将图像上传到数据库 当我单击“提交”按钮时,出现一个错误,您没有选择要上载的文件 我的代码怎么了 提前感谢,请帮助任何人。控制器 if ((isset($_FILES['userfile']['name'])) && ($_FILES['userfile']['name'] != "")) { $file = "user

控制器

这部分连接到我的数据库

看法

编程语言:PHP Codeigniter 服务器:XAMPP

我是初学者

问题:如何将图像上传到数据库

当我单击“提交”按钮时,出现一个错误,您没有选择要上载的文件

我的代码怎么了

提前感谢,请帮助任何人。

控制器

    if ((isset($_FILES['userfile']['name'])) && ($_FILES['userfile']['name'] != "")) {
                $file = "userfile";
                $path = './uploads/file/' ;
                $uploadedimages = $this->upload_image($file, $path, 1);
                $data['image'] = $uploadedimages['file_name'];
    }
/*上传文件功能*/

public function upload_image($file, $path, $thumb) {

        /* Upload file  in posted */
        $this->load->library('image_lib');
        $this->load->library('upload');

        $image_upload_folder = $path;

        if (!file_exists($image_upload_folder)) {
            mkdir($image_upload_folder, DIR_WRITE_MODE, true);
        }
        @chmod($image_upload_folder, 0777);
        $this->upload_config = array(
            'upload_path' => $image_upload_folder,
            'allowed_types' => '*',
            'remove_space' => TRUE,
            'encrypt_name' => TRUE,
        );

        $this->upload->initialize($this->upload_config);

        if (!$this->upload->do_upload($file)) {
            $upload_error = $this->upload->display_errors();
            echo ($upload_error);

        } else {
            $file_info = $this->upload->data();

            if ($thumb == 1) {

                $this->image_lib->clear();
                $config['image_library'] = 'GD2';
                $config['source_image'] = $image_upload_folder . '/' . $file_info['file_name'];
                $config['create_thumb'] = TRUE;
                $config['thumb_marker'] = '_thumb';
                $config['master_dim'] = 'width';
                $config['quality'] = 100;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 150;
                $config['height'] = 150;
                $config['new_image'] = $file_info['file_name'];

                //$this->image_lib->clear();
                //move_uploaded_file($value['full_path'], '/uploads/' . $newimagename);
                $this->image_lib->initialize($config);
                //$this->load->library('image_lib', $config);
                if (!$this->image_lib->resize()) {

                    $this->image_lib->clear();
                    $data['file_name'] = $file_info['file_name'];
                    $data['file_thumb'] = $file_info['file_name'];


                } else {
                    $upload_error = $this->image_lib->display_errors();
                                       $data['file_name'] = $file_info['file_name'];
                    $thmb = explode(".", $data['file_name']);
                    $data['file_thumb'] = $thmb[0] . "_thumb." . $thmb[1];
                }


                return $data;
            } else {
                return $file_info['file_name'];
            }
        }
    }

在调用do_upload之前,请尝试打印$\u文件['userfile']['name']。它是否存储正确的文件名?
      <!-- Name -->
               <?php echo form_open_multipart('home/addemployee'); ?>
              <div class="box-body">
                <div class="form-group">
                  <label for="exampleInputFile">Photo</label>
                  <input type="file" name"userfile" id="exampleInputFile" required>
                </div>
              <div class="row">
                <div class="col-xs-4">
                    <input name="firstname" type="text" class="form-control" placeholder="First Name" required>
                  </div>
                  <div class="col-xs-4">
                    <input name="middlename" type="text" class="form-control" placeholder="Middle Name" required>
                  </div>
                  <div class="col-xs-4">
                    <input name="lastname" type="text" class="form-control" placeholder="Last Name" required>
                  </div>
                </div>      
         <input type="submit" name="submit" class="btn btn-primary pull-right" value="Submit">
            <?php echo form_close(); ?>
    if ((isset($_FILES['userfile']['name'])) && ($_FILES['userfile']['name'] != "")) {
                $file = "userfile";
                $path = './uploads/file/' ;
                $uploadedimages = $this->upload_image($file, $path, 1);
                $data['image'] = $uploadedimages['file_name'];
    }
public function upload_image($file, $path, $thumb) {

        /* Upload file  in posted */
        $this->load->library('image_lib');
        $this->load->library('upload');

        $image_upload_folder = $path;

        if (!file_exists($image_upload_folder)) {
            mkdir($image_upload_folder, DIR_WRITE_MODE, true);
        }
        @chmod($image_upload_folder, 0777);
        $this->upload_config = array(
            'upload_path' => $image_upload_folder,
            'allowed_types' => '*',
            'remove_space' => TRUE,
            'encrypt_name' => TRUE,
        );

        $this->upload->initialize($this->upload_config);

        if (!$this->upload->do_upload($file)) {
            $upload_error = $this->upload->display_errors();
            echo ($upload_error);

        } else {
            $file_info = $this->upload->data();

            if ($thumb == 1) {

                $this->image_lib->clear();
                $config['image_library'] = 'GD2';
                $config['source_image'] = $image_upload_folder . '/' . $file_info['file_name'];
                $config['create_thumb'] = TRUE;
                $config['thumb_marker'] = '_thumb';
                $config['master_dim'] = 'width';
                $config['quality'] = 100;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 150;
                $config['height'] = 150;
                $config['new_image'] = $file_info['file_name'];

                //$this->image_lib->clear();
                //move_uploaded_file($value['full_path'], '/uploads/' . $newimagename);
                $this->image_lib->initialize($config);
                //$this->load->library('image_lib', $config);
                if (!$this->image_lib->resize()) {

                    $this->image_lib->clear();
                    $data['file_name'] = $file_info['file_name'];
                    $data['file_thumb'] = $file_info['file_name'];


                } else {
                    $upload_error = $this->image_lib->display_errors();
                                       $data['file_name'] = $file_info['file_name'];
                    $thmb = explode(".", $data['file_name']);
                    $data['file_thumb'] = $thmb[0] . "_thumb." . $thmb[1];
                }


                return $data;
            } else {
                return $file_info['file_name'];
            }
        }
    }