FPDF&&条码

时间:2017-06-21 12:31:58

标签: php barcode fpdf

我有一点问题,我使用库pi_barcode.php来生成条形码,而fpdf能够利用条形码并打印它,但是,我有一个库pi_barcode.php的问题, c'如果我把我的文件放在它工作的服务器的根目录上,但是图像的记录是在根目录下完成的,但是如果我的文件被放在一个文件夹中,那么它想要更多的保存它但是他显示它对我来说都一样。基本上我想要的是能够保存图像生成条形码在特定文件夹而不是服务器的根目录。

_cb.php:

require('pi_barcode.php');

     $code = $_GET['c'] ;

// ***** Création de l'objet
        $objCode = new pi_barcode();

        // ***** Hauteur, [Largeur]
        $objCode->setSize(25);

        // ***** Autres arguments
        $objCode->setText('');
        $objCode->hideCodeType();


        $objCode -> setType('C39');
        $objCode -> setCode($code);
        //Affichage //
        $objCode -> showBarcodeImage();
        //Enregistrement//
        $objCode->writeBarcodeFile($code . '.png');

上面的代码将图像保存到服务器的根目录,如果文件只在服务器的根目录下。

如果文件_cb.php在文件夹中,则不再进行注册,只显示。

以下是代码pi_barcode.php

/* Show image */

function showBarcodeImage()
        {
            $this->checkCode();
            $this->encode();

            if ($this->FILETYPE == 'GIF')
            {
                Header( "Content-type: image/gif");
                imagegif($this->IH);
            }
            elseif ($this->FILETYPE == 'JPG')
            {
                Header( "Content-type: image/jpeg");
                imagejpeg($this->IH);
            }
            else
            {
                Header( "Content-type: image/png");
                imagepng($this->IH);
            }
        }

        /**
        * Save Image
        */
        function writeBarcodeFile($file)
        {
            $this->checkCode();
            $this->encode();

            if ($this->FILETYPE == 'GIF')     imagegif($this->IH, $file);
            elseif ($this->FILETYPE == 'JPG') imagejpeg($this->IH, $file);
            else                              imagepng($this->IH, $file);
        }

以下代码是显示和保存条形码所需的功能

非常感谢你的帮助!

1 个答案:

答案 0 :(得分:0)

您应该将完整路径写入

$objCode->writeBarcodeFile($code . '.png');

$path     = '/myfolder/';
$filename = 'picture';
$objCode->writeBarcodeFile($path.filename. '.png');