我试图在我的网站上为每个用户创建一个上传文件夹,并在特定区域显示他们的照片。我已经能够得到编码器上传助手的工作,可以将文件上传到文件夹。现在我想要能够:
-
将特定用户上传的照片放在该用户动态创建的特定于其id的文件夹中
-
自动调整照片大小为两种尺寸。缩略图和更大的尺寸
我想我已经从如何做那些事情的研究中建立了它,我只是不知道如何在语法上插入他们的id以及创建一个文件夹并上传它。
最后一步将显示这些照片在我选择的位置绑定他们的id。
这是我的控制器
public function upload()
{
mkdir('./upload/' . $this->session->userdata('id'), 0777);
$config['image_library'] = 'gd2';
$config['source_image'] = 'PATH TO FOLDER??';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$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())
{
$error = array('error' => $this->upload->display_errors());
$data['main_content'] = 'account/upload';
$this->load->view('includes/templates/main_page_template', $data);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
您正在创建用户目录,但没有将其设置为上传路径…
$user_folder = './upload/' . $this->session->userdata('id');
if(!is_dir($user_folder)){
mkdir($user_folder, 0777);
}
...
$config['upload_path'] = $user_folder;
....