CodeIgniter上传图像错误

时间:2016-07-22 08:24:48

标签: php codeigniter

我正在尝试创建缩略图并将其保存在目标位置。但是当我试图保存它时,它给了我一个错误。

message error: <p>Unable to save the image. Please make sure the image and file directory are writable.</p>

这是我的代码:

控制器

public function insert_new_employee(){
    //users table
    $user_role_id = $this->input->post('user_role');
    $username = $this->input->post('username');
    $password = $this->input->post('password');


    //personal info
    $file_path = md5(date('Y-m-d H:i a'));
    $type = explode("/", $_FILES["image_path"]['type']);

    $first_name = $this->input->post('first_name');
    $last_name = $this->input->post('last_name');
    $employee_code = $this->input->post('employee_code');
    $gender = $this->input->post('gender');
    $position = $this->input->post('position');
    $birthdate = $this->input->post('birthdate');
    $email = $this->input->post('email');
    $avatar = $_FILES['image_path']['tmp_name'];

    $this->user_role_m->do_resize($avatar);
}

模型

public function do_resize($filename)
{
    $source_path = $filename;
    $target_path = base_url()."includes/avatars/thumbnail/";
    $config_manip = array(
        'image_library' => 'gd2',
        'source_image' => $source_path,
        'new_image' => $target_path,
        'maintain_ratio' => TRUE,
        'create_thumb' => TRUE,
        'thumb_marker' => '_thumb',
        'width' => 150,
        'height' => 150
    );
    $this->load->library('image_lib', $config_manip);
    if (!$this->image_lib->resize()) {
        echo $this->image_lib->display_errors();
    }
    // clear //
    $this->image_lib->clear();
}

这是我第一次遇到这个错误..所以请耐心等待...我还试图检查目标文件夹的权限,chmod是完全控制的......

0 个答案:

没有答案