Codeigniter 多文件上传路径 [英] Codeigniter multiple file upload paths

查看:19
本文介绍了Codeigniter 多文件上传路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序,它需要获取上传的文件并将它们放在缩略图和全尺寸图像的单独目录中.但是 $config['upload_path'] = './uploads/';只允许我选择一个上传路径.如何定义两个或多个上传路径?

I'm building an app which needs to take uploaded files and put them in separate directories for thumbnails and fullsize images. But $config['upload_path'] = './uploads/'; only allows me to select one upload path. How do I define two or more upload paths?

推荐答案

其实你需要做的就是重新初始化"上传类.Codeigniter 不允许您使用新参数调用该类两次(它忽略第二个请求),但是您可以告诉该类手动加载新参数.以下是基础知识:(注意$this->upload->initialized($config)"这一行,这是关键.

Actually all you need to do is "re-initialize" the upload class. Codeigniter does not allow you to call the class twice with new parameters (it ignores the second request), however you can tell the class to manually load new parameters. Here are the basics: (notice the line "$this->upload->initialized($config)" This is the key.

// this is for form field 1 which is an image....
$config['upload_path'] = './uploads/path1';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->upload->initialize($config); 
$this->upload->do_upload($fieild_1);

// this is for form field 2 which is a pdf
$config['upload_path'] = './pdfs/path2';
$config['allowed_types'] = 'pdf';
$config['max_size'] = '300';
$this->upload->initialize($config); 
$this->upload->do_upload($fieild_2);

我在这里写了一篇关于它的整篇文章:http://taggedzi.com/articles/display/multiple-file-uploads-using-codeigniter

I wrote an entire article about it here: http://taggedzi.com/articles/display/multiple-file-uploads-using-codeigniter

您可以在第二个初始化脚本中更改任何允许的参数,以便您的第二个文件可以具有完全不同的结构.您可以根据需要多次执行此操作,只需为每种文件类型重新初始化即可.(如果你愿意,你甚至可以设置一个配置数组并循环...)

You can change any of the allowed parameters in your second initialize script so that your second file can be of a completely different makeup. You can do this as many times as you like you just have to re-initialized for each file type. (You can even setup a config array and loop through if you like...)

希望这会有所帮助.

这篇关于Codeigniter 多文件上传路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆