将生成的QR码图像保存到路径中

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将生成的QR码图像保存到路径中相关的知识,希望对你有一定的参考价值。

我正在从数据库动态生成QR代码,我需要将它们存储在指定的路径中。当我生成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 .= "
";

        $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);
            }
        }
答案

希望对你有帮助 :

你的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 .= "
";

        $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

以上是关于将生成的QR码图像保存到路径中的主要内容,如果未能解决你的问题,请参考以下文章

通过在图像标签中传递链接生成 QR 码扫描仪

如何将我生成的 QR 图像保存到图库中?使用颤振

无法使用 swift 在 Facebook 上发布 QR 码图像

PowerShell:在Windows 10中为Wi-Fi网络生成QR代码

Tutorial中代码的区别及不同效果

如何通过单击适配器类中代码的项目中的删除按钮来删除列表视图中的项目后重新加载片段?