我有Codeigniter自定义系统,需要上传图像标准尺寸+创建_thumb到同一文件夹中,不重复。这是没有拇指图像创建器的工作代码...你能帮助我吗?
public function image($var, $id) {
$config['upload_path'] = './cdn/' . $this->module;
$config['allowed_types'] = 'gif|jpg|png|jpeg|webp';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('featured_image')) {
} else {
$data = $this->upload->data();
if ($data['file_name'])
$this->{$this->model}->featured_image = $data['file_name'];
}
return true;
}
public function image_upload() {
$config['upload_path'] = './cdn/' . $this->module;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$this->load->library('upload', $config);
$errors = 0;
$error_message = '';
$passed_files = [];
$var = 'file';
$files = $this->reArrayFiles(@$_FILES[$var]);
foreach ($files as $idx => $file) {
$_FILES[$var] = $files[$idx];
if ($this->upload->do_upload($var)) {
$data = $this->upload->data();
if ($data['file_name']) {
$ext = pathinfo($data['file_name'], PATHINFO_EXTENSION);
$file_name = "IRecipes_" . str_replace([".", " "], "", microtime()) . rand(0, 100) . "_orig." . $ext;
rename($data["full_path"], $data["file_path"] . $file_name);
$passed_files[] = $file_name;
}
} else {
$errors++;
$error_message .= strip_tags($this->upload->display_errors());
}
}
if ($passed_files && count($passed_files))
$this->uploadFile[$var] = ($passed_files);
if ($errors == count($files))
die(json_encode(["error" => true, "message" => $error_message]));
else
die(json_encode(["error" => false, "files" => $passed_files]));
}