默认情况下,我如何为Codeignitor中的上传类提供上传文件(例如从数据库上传),如果用户不上传任何默认文件,则应考虑使用Codeigniter。
感谢帮助。 :)
例如,
我将基于用户配置文件模块向您解释。
在您的上传文件夹中放置默认图像,假设
/www/uploads/images/no-avatar.png
在您的控制器上,您可以执行以下操作:
$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);
if ( ! $this->upload->do_upload('image')) // <input name="image" ... />
{
$user['image'] = 'no-avatar.png';
}
else
{
$data = array('upload_data' => $this->upload->data());
$user['image'] = $data['file_name'];
}
// then you store the value in the database
简而言之,所有用户都有相同的默认头像,如果他们上传自己的头像,后者将覆盖默认头像。