使用codeigniter将生成的条形码图像保存在数据库和文件夹中

问题描述:

我已使用图库来生成条形码。生成条形码,但问题是如何保存生成的图像?

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?

尽可能帮助儿子。

谢谢!

我得到解决方案

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';
}

使用imgepng函数存储图像。

它会将条形码图像存储在条码文件夹中。

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