使用Codeigniter和Nginx加载图像的问题

时间:2017-10-23 23:55:49

标签: php codeigniter nginx

我刚刚将普通的Apache服务器迁移到Nginx的服务器,该服务器的网站配置了Codeigniter。在此站点内,有一个控制器,使用Codeigniter的上载库处理图像上载。缺点是只使用Apache时正确加载的图像。但现在,使用nginx,相同的控制器(没有更改任何内容)表示图像正确加载但在应保存的文件夹中没有图像。

知道为什么会出现这种情况吗?

这是我的控制器的代码:

            $data['username'] = $this->session->userdata['username'];
            $data['password'] = $this->session->userdata['password'];
            $email = $data['username'];

            $config['upload_path'] = './uploads_imgperfil/';
            $config['allowed_types'] = 'gif|jpg|png|jpeg';
            $config['file_name'] = 'imagen';
            $config['overwrite'] = TRUE;
            $config['max_size'] = 3000;
            $config['max_width'] = 2048;
            $config['max_height'] = 2048;

            $this->load->library('upload', $config);

            if ($this->upload->do_upload("file")) {

                $fileName = $_POST['fileName'];

                //Obtengo la extensión del archivo
                $extension = pathinfo($fileName, PATHINFO_EXTENSION);

                //Obtengo el ID del candidato
                $name_candidato = $this->model_edicion_perfil->obtener_name($data['username']);
                $id_registro = $name_candidato->idcandidato;

                $thumb = '_'.$id_registro;

                $configx['image_library'] = 'gd2';
                $configx['source_image'] = './uploads_imgperfil/imagen.'.$extension;
                $configx['create_thumb'] = TRUE;
                $configx['thumb_marker'] = $thumb;
                $configx['maintain_ratio'] = TRUE;
                $configx['width'] = 310;
                $configx['height'] = 233;

                $this->load->library('image_lib', $configx);
                $this->image_lib->resize();

                //Por ultimo borro la imagen que el subio
                unlink('./uploads_imgperfil/imagen.'.$extension);

                $image_name = 'imagen_'.$id_registro.'.'.$extension;

                $data = array(
                    'image_perfil' => $image_name
                );

                $consulta = $this->model_edicion_perfil->update_imgperfil($email, $data);
                $this->ultima_actualizacion($email);

                $result = array(
                    'message' => 'Imagen cargada correctamente.',
                    'flag' => 1,
                    'image' => $image_name
                );

            }else{

                $result = array(
                    'message' => $this->upload->display_errors(),
                    'flag' => 0
                );

            }

我的nginx配置文件如下所示:

server {
    ## Escucha en el puerto 80 (HTTP)
    listen   80;

    ## Raíz donde se encuentra la página Web
    root /var/www/example.com/public_html/example;

    ## Orden de prioridad de los archivos index
     index index.php index.html index.htm index.nginx-debian.html;

    server_name example.com;

     location / {
      #  index index.php index.html index.htm index.nginx-debian.html;
       try_files $uri $uri/ /index.php;
    }

      location ~ \.php$ {
        include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/run/php/php7.0-fpm.sock;
     }

     location ~ /\.ht {
         deny all;
     }

}

提前致谢!

0 个答案:

没有答案