【问题标题】:How to make a user upload folder and display specific content in codeigniter?如何让用户上传文件夹并在codeigniter中显示特定内容?
【发布时间】:2013-03-19 17:35:48
【问题描述】:

我正在尝试为我网站上的每个用户创建一个上传文件夹,并在特定区域显示他们的照片。我已经能够让 codeigniter 上传助手工作,并且可以将文件上传到文件夹。现在我希望能够:

  1. 将特定用户上传的照片放置在为该用户动态创建的特定于其 ID 的文件夹中

  2. 自动调整两种尺寸的照片大小。缩略图和更大尺寸

我想我已经通过研究如何做那些我不知道如何在语法上插入他们的 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);
        }
    }

【问题讨论】:

    标签: php codeigniter file-upload


    【解决方案1】:

    您正在创建用户目录但未将其设置为上传路径...

    $user_folder = './upload/' . $this->session->userdata('id');
    if(!is_dir($user_folder)){
        mkdir($user_folder, 0777);
    }
    ...
    $config['upload_path'] = $user_folder;
    ....
    

    【讨论】:

    • 这是有效的,但是我仍然收到一个错误:“严重警告:mkdir()[functon.mkdir]:文件存在
    • 在尝试创建之前检查目录是否存在。我会更新答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    • 2017-03-31
    • 2013-06-14
    • 1970-01-01
    • 1970-01-01
    • 2016-05-19
    相关资源
    最近更新 更多