php - 编辑时如何处理双图像文件
问题描述
当我编辑图像文件时,它会在文件夹中复制文件,有谁知道如何处理它?
控制器
**public function editHome()
{
$config['upload_path'] = './upload/images/slide/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
//edit
$id_home = $this->input->post('id_home1', true);
$data['dm'] = $this->db->get_where('tb_home', ['id_home' => $id_home])->row_array();
if (!$this->upload->do_upload('gambar_home')) {
echo "Gagal Update";
} else {
$dd = array('upload_data' => $this->upload->data());
$dm = [
'judul_home' => $this->input->post('judul_home'),
'gambar_home' => $dd['upload_data']['file_name'],
'desc_home' => $this->input->post('desc_home'),
'status_home' => $this->input->post('status_home')
];
$this->db->where('id_home', $this->input->post('id_home', true))->update('tb_home', $dm);
}
$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert"> Berhasil Update !</div>');
redirect('admin/content/home');
}**
解决方案
默认情况下,codeigniter 文件上传库不会替换上传的同名文件,而是使用[filename]1.jpg
. 如果文件名相同,您可以使用以下命令替换它:
$config['overwrite'] = true; //set true to overwrite the data
$config['upload_path'] = './upload/images/slide/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
推荐阅读
- angularjs - Angularjs:多指令资源争用
- python - strptime 错误,例如这次数据 '01–MAY-21' 与格式 '%d-%b-%y' 不匹配
- unity3d - 使用 [Command] 将游戏对象从客户端发送到服务器
- mongodb - 获取集合有数组元素存在另一个集合
- logging - 如何使用 Quarkus 拦截日志消息以进行测试
- instagram - 当 Instagram 用户使用取消授权回调 url 取消授权我的应用程序时,取消授权回调向我发送不同的用户 ID
- python - 如何在 PyCharm 中使用 databricks utils 函数?我找不到合适的 pip 包
- bash - 使用 bash 脚本通读文件并检查确切位置
- python - HTTPS - 无法获取索引基本 URL https://pypi.python.org/simple/
- python - 从 Pandas DataFrames 中的表列表中返回具有特定“列标题”的表