# CodeIgniter 文件上传类 - 偏好设置

**URL:** <https://www.isharkfly.com/t/codeigniter/5151>\
**Category:** PHP\
**Created:** [January 8, 2014, 2:32am UTC](https://www.isharkfly.com/t/codeigniter/5151 "2014-01-08T02:32:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [January 8, 2014, 2:32am UTC](https://www.isharkfly.com/t/codeigniter/5151/1 "2014-01-08T02:32:13Z")

</div>

与其它库类似，你将根据你的偏好设置来控制要被上传的文件，在控制器里，你建立了如下的偏好设置：[code]$config[‘upload\_path’] = ‘./uploads/’;  
$config[‘allowed\_types’] = ‘gif|jpg|png’;  
$config[‘max\_size’] = ‘100’;  
$config[‘max\_width’] = ‘1024’;  
$config[‘max\_height’] = ‘768’;

$this-\>load-\>library(‘upload’, $config);

// Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:  
//【如果你在 config文件夹内的 autoload.php 文件中自动加载了 upload 类，或者在构造函数内加载了的话，可以调用初始化函数 initialize 来加载设置。————本括号内由IT不倒翁翻译，加入了自己的理解】  
$this-\>upload-\>initialize($config);[/code]以上偏好设置将被完全执行。以下是所有偏好设置参数的描述。

文章来源：[http://cwiki.ossez.com/pages/viewpage.action?pageId=2392149](http://cwiki.ossez.com/pages/viewpage.action?pageId=2392149)
