如何在 Codeigniter 中上传的文件名中添加前缀?
我的网站上有一个文件上传表单,希望在用户上传照片时在文件名的开头添加前缀。
我已经设置了上传配置(见下文),但不确定如何设置前缀。
我最好不想打扰 ['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);
总是非常感谢帮助。
I have a file upload form on my website and would like to add a prefix to the beginning of the file name when a user uploads a photo.
I have set my configuration for the upload (see below) but am unsure how to set a prefix.
I preferably do not want to disturb the ['encrypt_name'] as this saves me time and effort making unique names but prefix to the beginning of the encrypted name. I will be adding the users id to the beginning.
$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);
Help always greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 $this->upload->data() 获取文件名可能是最简单的,然后使用 php rename() 将 id 添加到开头。
像这样的东西:
It's probably easiest to get the filename using $this->upload->data(), and then using php rename() to add the id to the beginning.
Something like this: