Save generated bar code image in database and in folder using codeigniter

浪子不回头ぞ 提交于 2019-12-18 18:31:34

问题


I have used library to generate barcode. Bar code is generated but problem is that how can i save that generated image?

Here i am giving my code i have used:

In controller:

function add($bar_code)
{
   $postData['bar_code'] = $this->set_barcode($postData['bar_code']);
}

function set_barcode($code)
{
    $this->load->library('zend');
    $this->zend->load('Zend/Barcode');
    $bar_code = Zend_Barcode::render('code128', 'image', array('text'=>$code), array('imageType' => 'jpg'))->draw();
    return $bar_code;
}

How can i save the image of generated bar code?

Help as son as possible.

Thanks!


回答1:


I got the solution:

function set_barcode($code)
{
   $this->load->library('zend');
   $this->zend->load('Zend/Barcode');
   $file = Zend_Barcode::draw('code128', 'image', array('text' => $code), array());
   $code = time().$code;
   $store_image = imagepng($file,"../barcode/{$code}.png");
   return $code.'.png';
}

store the image using imgepng function.
it will store the bar code image in barcode folder.



来源:https://stackoverflow.com/questions/29084609/save-generated-bar-code-image-in-database-and-in-folder-using-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!