php - 在 codeigniter 中上传图像时覆盖以前的文件

标签 php image codeigniter overwrite

我在 codeigniter 中上传图片,效果很好。但是当我尝试更新图像时,codeigniter 会自动在每个图像的末尾添加 1。这将在我的图像目录中添加未使用的图像。我怎样才能覆盖现有图像而不是给它一个新名称并保存它?

最佳答案

您应该提供overwrite 配置参数

$config['upload_path'] = './uploads/';
$config['overwrite'] = TRUE;

$this->load->library('upload', $config);

$this->upload->initialize($config);

参见 Documentation上传偏好

Preference: overwrite

Default Value: FALSE

Options: TRUE/FALSE (boolean)

Description: If set to true, if a file with the same name as the one you are uploading exists, it will be overwritten. If set to false, a number will be appended to the filename if another with the same name exists.

关于php - 在 codeigniter 中上传图像时覆盖以前的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17575999/

相关文章:

javascript - 如何将这种特定类型的数据添加到 MySQL 中

mysql - 如何在 session 变量中更新更改的用户名而不注销或 session 销毁

php - 如何检查 PNG 的灰度/alpha 颜色类型?

php:编写 .ics (iCal) 文件?日期格式?

php - 执行查询没有结果也没有错误

android - 显示 ListView 时在后台下载图像

java - 我想在 Java 中的图像上创建一个不可见的可点击对象

c - 将二进制文件读入同一个后Unsigned Char为(null)

php - 带有 nginx 的 Codeigniter 为嵌套应用程序提供 404 错误

PHP 匹配 2 选定的表