我有一个用户可以注册的页面。他在此过程中上传个人资料照片。我想限制大小,但除了$ config ['maxsize']之外,没有太多重点放在codeigniter文档上。我尝试了以下,但我没有收到任何消息。为了测试,我将大小设置为10(KB)。我是否必须以某种方式处理它以将信息传达给我的观点?codeigniter中的上传大小限制
public function add_user()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '10';
//$config['max_width'] = '1024';
//$config['max_height'] = '768';
$this->load->library('upload', $config);
$fullImagePath;
if (isset($_FILES['userfile']) && !empty($_FILES['userfile']['name']))
{
if ($this->upload->do_upload('userfile'))
{
// set a $_POST value for 'image' that we can use later
...
顺便说一下,这段代码是在我的模型中。
为什么你要保持它在你的模型....? – 2013-04-25 06:46:11
我只是测试功能..我知道它应该在控制器中。我将稍后迁移 – 2013-04-25 06:47:02
当您超出maxsize字段中指定的大小时,请遵循此链接http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html CI将自动给出错误........ – 2013-04-25 06:47:58