在require目录php中保存条形码图像

时间:2015-05-12 07:06:24

标签: php

我正在使用php中的条形码项目。我的问题是,当我点击test.php时,条形码图像与我的php文件目录保存在同一目录中:

/demo1/demo2/demo3/demo4/file1/file2/file3/barcodeimage.png
/demo1/demo2/demo3/demo4/file1/file2/file3/test.php

但我需要在此路径中保存barcodeimage.png:

/demo1/demo2/demo3/demo4/image1/image2/image3/barcodeimage.png

为方便起见,我更改目录名称

以下是代码:

<?php
$codeTexttwo = '1234567890.png';
$drawException = null;
try {
    $color_black = new BCGColor(0, 0, 0);
    $color_white = new BCGColor(255, 255, 255);

    $code_generated = new $className();

    if (function_exists('baseCustomSetup')) {
        baseCustomSetup($code_generated, $default_valuetwo);
    }

    if (function_exists('customSetup')) {
        customSetup($code_generated, $default_valuetwo);
    }

    $code_generated->setScale(max(1, min(4, $default_valuetwo['scale'])));
    $code_generated->setBackgroundColor($color_white);
    $code_generated->setForegroundColor($color_black);

    if ($default_valuetwo['texttwo'] !== '') {
        $text = convertText($default_valuetwo['texttwo']);
        $code_generated->parse($text);
    }

} catch(Exception $exception) {
    $drawException = $exception;
}
$fileNameBCtwo = $codeTexttwo.".png";

$drawing = new BCGDrawing($fileNameBCtwo, $color_white);


if($drawException) {
    $drawing->drawException($drawException);
} else {
    $drawing->setBarcode($code_generated);
    $drawing->setRotationAngle($default_valuetwo['rotation']);
    $drawing->setDPI($default_valuetwo['dpi'] === 'NULL' ? null : max(72, min(300, intval($default_valuetwo['dpi']))));
    $drawing->draw();
$drawing->finish();
}

$drawing->finish($filetypes[$default_valuetwo['filetype']]);

?>

1 个答案:

答案 0 :(得分:0)

更改此行:

$fileNameBCtwo = $codeTexttwo.".png";

到此:

$fileNameBCtwo = '/demo1/demo2/demo3/demo4/image1/image2/image3/' . $codeTexttwo.".png";

检查该目录的文件夹权限