0

我正在从数据库动态生成 QR 码,我需要将它们存储在指定的路径中。当我生成二维码并单独保存时,但现在批量生成它们时,我需要将它们存储在我的首选路径中。我怎样才能做到这一点?

这是我的功能

function print_qr1(){
    $qr_code_config = array();
    $qr_code_config['cacheable']    = $this->config->item('cacheable');
    $qr_code_config['cachedir']     = $this->config->item('cachedir');
    $qr_code_config['imagedir']     = $this->config->item('imagedir');
    $qr_code_config['errorlog']     = $this->config->item('errorlog');
    $qr_code_config['ciqrcodelib']  = $this->config->item('ciqrcodelib');
    $qr_code_config['quality']      = $this->config->item('quality');
    $qr_code_config['size']         = $this->config->item('size');
    $qr_code_config['black']        = $this->config->item('black');
    $qr_code_config['white']        = $this->config->item('white');
    $this->ci_qr_code->initialize($qr_code_config);

    // get full name and user details
    $user_details['doctordata'] = $this->user->get_users();
    foreach ($user_details['doctordata'] as $value) {
        $image_name = $value->DOCTORCODE . ".png";

        $codeContents = "www.36d.co.in/qr_code=";
        $codeContents .= $value->DOCTORCODE;
        $codeContents .= "\n";

        $params['data'] = $codeContents;
        $params['level'] = 'H';
        $params['size'] = 10;

        $params['savename'] = FCPATH . $qr_code_config['imagedir'] . $image_name;
        $this->ci_qr_code->generate($params);

        $this->data['qr_code_image_url'] = base_url() . $qr_code_config['imagedir'] . $image_name;

        // save image path in tree table
        $this->user->change_userqr($value->DOCTORCODE);
        // then redirect to see image link
        $file = $params['savename'];
         function do_upload($file){
            $config['upload_path']          = './uploads/qrcode/';
            $config['allowed_types']        = 'png';
            $config['max_size']             = 0;
            $config['max_width']            = 0;
            $config['max_height']           = 0;

            $this->load->library('upload', $config);

            if ( ! $this->upload->do_upload($file))
            {
                    $error = array('error' => $this->upload->display_errors());

                    $this->load->view('upload_form', $error);
            }
            else
            {
                    $data = array('upload_data' => $this->upload->data());

                    $this->load->view('upload_success', $data);
            }
        }
4

1 回答 1

1

希望这会帮助你:

你的print_qr1方法应该是这样的:

function print_qr1()
{
    $qr_code_config = array();
    $qr_code_config['cacheable']    = $this->config->item('cacheable');
    $qr_code_config['cachedir']     = $this->config->item('cachedir');
    $qr_code_config['imagedir']     = $this->config->item('imagedir');
    $qr_code_config['errorlog']     = $this->config->item('errorlog');
    $qr_code_config['ciqrcodelib']  = $this->config->item('ciqrcodelib');
    $qr_code_config['quality']      = $this->config->item('quality');
    $qr_code_config['size']         = $this->config->item('size');
    $qr_code_config['black']        = $this->config->item('black');
    $qr_code_config['white']        = $this->config->item('white');
    $this->ci_qr_code->initialize($qr_code_config);

    // get full name and user details
    $user_details['doctordata'] = $this->user->get_users();
    foreach ($user_details['doctordata'] as $value) {
        $image_name = $value->DOCTORCODE . ".png";

        $codeContents = "www.36d.co.in/qr_code=";
        $codeContents .= $value->DOCTORCODE;
        $codeContents .= "\n";

        $params['data'] = $codeContents;
        $params['level'] = 'H';
        $params['size'] = 10;

        $params['savename'] = FCPATH . $qr_code_config['imagedir'] . $image_name;
        $this->ci_qr_code->generate($params);

        $this->data['qr_code_image_url'] = base_url().$qr_code_config['imagedir']. $image_name;

        // save image path in tree table
        $this->user->change_userqr($value->DOCTORCODE);
        // then redirect to see image link
        $file = $params['savename'];
        my_upload($file);
    }
}

这是你的my_upload方法

function my_upload($file)
{
    $config['upload_path']          = './uploads/qrcode/';
    $config['allowed_types']        = 'png';

    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload($file))
    {
        $error = array('error' => $this->upload->display_errors());

        $this->load->view('upload_form', $error);
    }
    else
    {
        $data = array('upload_data' => $this->upload->data());

        $this->load->view('upload_success', $data);
    }
}

更多信息:https ://www.codeigniter.com/user_guide/libraries/file_uploading.html

于 2018-08-02T14:10:16.820 回答