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

查看:118
本文介绍了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

您可以更改第二个初始化脚本中的任何允许的参数,以便第二个文件可以完全不同。你可以这么多次,你喜欢你只需要重新初始化为每个文件类型。 (你甚至可以设置一个配置数组,并循环通过,如果你喜欢...)

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天全站免登陆