我正在尝试为将上传到我的服务器的图像创建缩略图。请参阅https://www.codeigniter.com/userguide3/libraries/image_lib.html#processing-an-image。创建后,我想将缩略图保存到另一个文件夹,因为原始图像和缩略图都将保存在同一位置。
所以,我尝试使用move_uploaded_file()
函数,但它无法移动文件。我不确定我的代码是否正确完成。看看这个。
Belwo 是我的代码:
if($_FILES['file_name']['size'] != 0){
$config['upload_path'] = FCPATH.MEDIA_LIB_URI.'facts';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['max_size'] = 0;
$newFileName = removeExt($_FILES['file_name']['name']).'-'.uniqueId(); // renaming the file name without the ext
$new_name = $newFileName.getExt($_FILES['file_name']['name']); // new file name with the ext
$config['file_name'] = $new_name;
$this->load->library('upload',$config);
$this->upload->initialize($config);
if($this->upload->do_upload('file_name')){
$uploadData = $this->upload->data();
$file_name = $uploadData['file_name'];
$this->load->library('image_lib');
$configer = array(
'image_library' => 'gd2',
'source_image' => $uploadData['full_path'],
'create_thumb' => TRUE,
'maintain_ratio' => TRUE,
'width' => 950,
'height' => 950,
);
$this->image_lib->clear();
$this->image_lib->initialize($configer);
$this->image_lib->resize();
$thumbName = $newFileName.'_thumb'.getExt($_FILES['file_name']['name']); // getting the exact thumbnail name that been created by codeigniter
move_uploaded_file($thumbName, FCPATH.MEDIA_LIB_URI.'facts/thumbnail/'.$new_name);
return $file_name;
} else {
return $this->upload->display_errors();
}
}