我需要您的帮助才能在我的网站中混合使用两种功能。我的目的是上传和调整图像大小。我有一个功能可以很好地处理用户图片,我还有另一个用于上传图片(列表或广告图片),但此功能不会创建缩略图。它只是上传它。我喜欢做的是像功能专用用户图片一样上传和调整大小。
希望您能够帮助我。这是有关用户图片的功能(拇指调整大小工作)
public function photo($id = "") {
$target_path = realpath(APPPATH . '../images/users');
//echo $target_path;
if (!is_writable(dirname($target_path))) {
$this->session->set_flashdata('flash_message', $this->Common_model->flash_message('error', 'Sorry! Destination folder is not writable.'));
redirect('users/edit', 'refresh');
} else {
if (!is_dir(realpath(APPPATH . '../images/users') . '/' . $id)) {
//echo $this->path.'/'.$id;
mkdir(realpath(APPPATH . '../images/users') . '/' . $id, 0777, true);
}
$target_path = $target_path . '/' . $id . '/userpic.jpg';
if ($_FILES['upload123']['name'] != '') {
move_uploaded_file($_FILES['upload123']['tmp_name'], $target_path);
$thumb1 = realpath(APPPATH . '../images/users') . '/' . $id . '/userpic_thumb.jpg';
GenerateThumbFile($target_path, $thumb1, 107, 78);
$thumb2 = realpath(APPPATH . '../images/users') . '/' . $id . '/userpic_profile.jpg';
GenerateThumbFile($target_path, $thumb2, 209, 209);
$thumb3 = realpath(APPPATH . '../images/users') . '/' . $id . '/userpic_micro.jpg';
GenerateThumbFile($target_path, $thumb3, 36, 36);
$this->session->set_flashdata('flash_message', $this->Common_model->flash_message('success', 'Your profile photo updated successfully.'));
redirect('users/edit', 'refresh');
} else {
$this->session->set_flashdata('flash_message', $this->Common_model->flash_message('error', 'Please browse your profile photo.'));
redirect('users/edit', 'refresh');
}
}
}
这是实现 resize 的函数 id :
if ($this->input->post()) {
$listId = $param;
$images = $this->input->post('image');
$is_main = $this->input->post('is_main');
$fimages = $this->Gallery->get_imagesG($listId);
if ($is_main != '') {
foreach ($fimages->result() as $row) {
if ($row->id == $is_main)
$this->Common_model->updateTableData('list_photo', $row->id, NULL, array("is_featured" => 1));
else
$this->Common_model->updateTableData('list_photo', $row->id, NULL, array("is_featured" => 0));
}
}
if (!empty($images)) {
foreach ($images as $key => $value) {
$image_name = $this->Gallery->get_imagesG(NULL, array('id' => $value))->row()->name;
unlink($this->path . '/' . $listId . '/' . $image_name);
$conditions = array("id" => $value);
$this->Common_model->deleteTableData('list_photo', $conditions);
}
}
if (isset($_FILES["userfile"]["name"])) {
$insertData['list_id'] = $listId;
if (!is_dir($this->path . '/' . $listId)) {
//echo $this->path.'/'.$id;
mkdir($this->path . '/' . $listId, 0777, true);
$insertData['is_featured'] = 1;
}
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->path . '/' . $listId,
'encrypt_name' => TRUE,
'remove_spaces' => TRUE
);
//echo $this->path.'/'.$id;
$this->load->library('upload', $config);
$data = $this->upload->do_upload();
if ($data) {
$this->outputData['file'] = $this->upload->data();
$insertData['name'] = $this->outputData['file']['file_name'];
$insertData['created'] = local_to_gmt();
if ($this->outputData['file']['file_name'] != '')
$this->Common_model->insertData('list_photo', $insertData);
}
}
}