Сохранить сгенерированное изображение 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 .= "\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);
}
}

0

Решение

Надеюсь, что это поможет вам:

Ваш 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

1

Другие решения

Других решений пока нет …