Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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_Codeigniter_Codeigniter 3 - Fatal编程技术网

Php 无法在Codeigniter中创建配置文件图像的缩略图(调整大小)

Php 无法在Codeigniter中创建配置文件图像的缩略图(调整大小),php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,当用户上传个人资料图片时,我试图为他创建一个个人资料缩略图。我在这里寻求一些帮助,最近我接触了Codeiniter,我对php也是新手 当前,这会将配置文件图像插入“temp”文件夹,但不会调整其大小。我可能做错了。我是否必须为缩略图创建一个新功能,或者我可以将其与我拥有的功能一起包括在内 我可以添加新的个人资料图片。添加新图片时,自动替换图片并删除配置文件图片。只需调整图像的大小(缩略图) 这是控制器: public function profile_image() { if($thi

当用户上传个人资料图片时,我试图为他创建一个个人资料缩略图。我在这里寻求一些帮助,最近我接触了Codeiniter,我对php也是新手

当前,这会将配置文件图像插入“temp”文件夹,但不会调整其大小。我可能做错了。我是否必须为缩略图创建一个新功能,或者我可以将其与我拥有的功能一起包括在内

我可以添加新的个人资料图片。添加新图片时,自动替换图片并删除配置文件图片。只需调整图像的大小(缩略图)

这是控制器:

public function profile_image() {
    if($this->session->userdata('is_logged_in')){
    $username = $this->session->userdata('v_member_username');
    $url1 = $this->my_profile_model->see_if_old_image_exists($username);

    if (empty($_FILES['profile_image']['tmp_name'])) {
        return true;
    }else{
        $url2  = $this->do_upload();
        $this->my_profile_model->update_profile_image($url2, $username);
        if(!empty($url1)){
        $this->my_profile_model->delete_old_profile_image($url1);
        }
        }
    }
}
private function do_upload() {
    $type = explode('.', $_FILES['profile_image']['name']);
    $type = $type[count($type)-1];
    $filename = uniqid(rand()).'.'.$type;
    $url2 = './uploads/temp/'.$filename;
    if(in_array($type, array('jpeg', 'gif', 'png', 'jpg')))
        if (empty($_FILES['profile_image']['tmp_name'])) {
    return TRUE;
    }else{
    if(is_uploaded_file($_FILES['profile_image']['tmp_name']))
        if(move_uploaded_file($_FILES['profile_image']['tmp_name'], $url2));

            return $url2;
    return '';
    // do_thumb
    $this->load->library('image_lib');
    $source_path = $_SERVER['DOCUMENT_ROOT'] . 'uploads/temp/' . $filename;
    $target_path = $_SERVER['DOCUMENT_ROOT'] . 'uploads/profile/';
    $config_manip = array(
        'image_library' => 'gd2',
        'source_image' => $source_path,
        'new_image' => $target_path,
        'maintain_ratio' => TRUE,
        'create_thumb' => TRUE,
        'thumb_marker' => '_thumb',
        'width' => 270,
        'height' => 263
    );
    $this->load->library('image_lib', $config_manip);
    if (!$this->image_lib->resize()) {
        echo $this->image_lib->display_errors();
    }
    // clear //
    $this->image_lib->clear();
    }
}
我的模型是:

// Update profile Image
    function update_profile_image($url2, $username){
        $this->db->set('profile_image', $url2);
        $this->db->where('v_member_username', $username);
        $this->db->update('vbc_registered_members');
    }
// Look If There Was Any Old Image Earlier
    function see_if_old_image_exists($username) {
        $this->db->select('profile_image');
        $this->db->from('vbc_registered_members');
        $this->db->where('v_member_username', $username);
        $query = $this->db->get();
        $query_result = $query->result();
        $row = $query_result[0];
        return $row->profile_image;
    }
// Auto Delete profile Image From Upload Folder On Updating New Image
    function delete_old_profile_image($url1) {
        unlink($url1);
        return TRUE;
    }

请告知。

Codeigniter提供了一个用于上传数据的库。 看到和

这是我用来上传图像、创建缩略图和调整图像大小的代码

/*
* This function returns the path of imagemagick on your system
*/
public static function getLibPath()
{
    if(strlen(self::$_lib_path)==0)
    {
        self::$_lib_path=exec("/bin/bash -lc '/usr/bin/which convert'",$out,$rcode);
    }
    return self::$_lib_path;
}

/*
* This function handles the upload and calls the resizeImage function
* to generate the thumbnail and the resized image
*/
public function update()
{
    $config['upload_path'] = 'your upload path';
    $config['allowed_types'] = 'jpg|png|bmp';
    $config['max_size'] = '8192';//8mb //4096kb - 4mb
    $config['max_width']    = '0';
    $config['max_height']  = '0';
    $config['overwrite'] = false;
    $config['encrypt_name']=true;//this generates a filename for you

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


    if($result) {
        $fileInfo=$this->upload->data();

        $this->resizeImage($fileInfo['full_path']);
        $data = array(
            'filename' => $fileInfo['file_name'],
            'orig_file_name' =>$fileInfo['orig_name'],
        );
        //pseudo function for storing the file info
        save_metadata_to_db($data);

    }
    else
    {
        echo $this->upload->display_errors());
    }
}
/*
* This function creates a thumbnail + the resized image
*/
private function resizeImage($filename)
{
   //This function creates a file with the orig. filename + _thumb

    $config['image_library'] = 'ImageMagick';
    $config['source_image'] = $filename;
    $config['create_thumb'] = TRUE;
    $config['maintain_ratio'] = FALSE;
    $config['width']    = 60;
    $config['height']   = 60;
    $config['library_path'] = $this->getLibPath();
    $config['quality'] = '100%';


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

    if ( ! $this->image_lib->resize())
    {
       echo $this->image_lib->display_errors());
    }


    $config['create_thumb'] = False;
    $config['maintain_ratio'] = TRUE;
    $config['width']    = 1080;
    $config['height']   = 1920;

    $this->image_lib->initialize($config);

    if ( ! $this->image_lib->resize())
    {
        echo $this->image_lib->display_errors());
    }
}

错误信息是什么response@Abdulla,没有错误消息。。。除了缩略图什么都做。