作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的网站上有一个文件上传表单,当用户上传照片时,我想在文件名的开头添加一个前缀。
我已经为上传设置了配置(见下文),但不确定如何设置前缀。
我最好不想打扰 ['encrypt_name'],因为这样可以节省我制作唯一名称的时间和精力,但可以在加密名称的开头加上前缀。我将在开头添加用户 ID。
$config['upload_path'] = $upload_path;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['encrypt_name'] = true;
$this->load->library('upload', $config);
帮助总是非常感谢。
最佳答案
可能最简单的方法是使用 $this->upload->data() 获取文件名,然后使用 php rename() 将 id 添加到开头。
像这样:
$upload_data = $this->upload->data();
rename(
$upload_data['full_path'],
$upload_data['file_path'].'/'.$user_id.'_'.$upload_data['orig_name']
);
关于codeigniter - 如何在 Codeigniter 中上传时为文件名添加前缀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8894345/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!