i am using the foreach loop to go through an Array that contains a set of bar code numbers.i would like to pass each of these numbers to a variable called "$value so that they can be pass to the image draw function witch will then draw a bar code image for each number.
but all that gets printed out is "NO UPC" Can somebody explain to me why?
it should only Print NO UPC if there is No UPC number.
here is a small part of the file that the bar code is being extracted from .
As you can see the bar code numbers are at the end. i am able to extract them successfully but have trouble passing them
to the "image draw function"
sm_a6000.jpg, A6000 B.G. CASSAREEP CASSAVA 12X425ML,048817002015
sm_a6003.jpg, A6003 GUYCAN CASSAREEP CASSAVA 12X425GR,069065000295
sm_a6006.jpg, A6006 GUYANESE PRIDE CASSAREEP POMEROON 24X425GR,069065000332
sm_a6009.jpg, A6009 CHICO CASSAREEP POMEROON 24X425GR,069065000325
sm_a6012.jpg, A6012 BROWN BETTY CASSAREEP POMEROON 24X375ML,069065001322
sm_a6014.jpg, A6014 BROWN BETTY CHINESE SAUCE 12X375ML,069065004200
sm_a6016.jpg, A6016 WEST INDIAN PRIDE MOLASSES 12X425GR,069065011093
sm_a6017.jpg, A6017 WEST INDIAN PRIDE BURNT SUGAR 12X425GR,069065002428
sm_a6019.jpg, A6019 BROWN BETTY BROWNING 24X148ML,069065002305
sm_a6021.jpg, A6021 BEDESSEE MANGO ACHAR 12X340GR,069065000103
HERE is my Code:
NOTE: the Area with the problem has been highlighted in read
<?php
require_once 'Image/Barcode.php';
$file = 'afiles.txt' or die('Could not read file!');
// read file into array
$data = file($file) or die('Could not read file!');
// loop through array and print each line
$numLines=count($data);
natcasesort($data);
$colCtr = 0;
$cols = 8; # Number of columns to display
$items=$_GET['items'];
$items=40;
$imageCount=0;
$pos =0;
$pos=$_GET['pos'];
if(!$pos){
$pos= 0;
}
$position = $pos * $items;
$data = array_unique($data);
$data1 = array_slice($data, $position, $items);
foreach ($data1 as $line) {
$temp = explode(",", $line);
$images=$temp[0];
$descriptions=$temp[1];
$value=$temp[2];
echo $value;
if(isValid($value)==true){
Image_Barcode::draw($value, 'upca', 'png');
}
else{
echo"NO UPC";
}
}
function isValid($value)
{
$valueString = (string) $value;
//$this->_setValue($valueString);
if ('' === $valueString) {
$error='STRING_EMPTY';
return false;
}
if (strlen($valueString) !== 12) {
$error='INVALID_LENGTH';
return false;
}
$barcode = substr($valueString, 0, -1);
$oddSum = 0;
$evenSum = 0;
for ($i = 0; $i < 11; $i++) {
if ($i % 2 === 0) {
$oddSum += $barcode[$i] * 3;
} elseif ($i % 2 === 1) {
$evenSum += $barcode[$i];
}
}
$calculation = ($oddSum + $evenSum) % 10;
$checksum = ($calculation === 0) ? 0 : 10-$calculation;
if ($valueString[11] != $checksum) {
$error='INVALID';
return false;
}
return true;
}
?>
SOMeBODY PLEASE help
Thanks in advance
Barcode image won't print
Moderator: General Moderators
Re: Barcode image won't print
I think you'll need to use trim() on $value before passing it to isValid().
The script still won't work after that though. You can't output more than one image in a script.
The script still won't work after that though. You can't output more than one image in a script.