 |
|
ก่อนอื่นต้องขออธิบายก่อน
ขั้นตอนแรก เข้าไปกรอกข้อมูลในฟอร์ม แล้วกด Submit จากนั้นฟอร์มก็จะเรียกฟังก์ชั่น encodeing() ขึ้นมา
Code (PHP)
function encoding()
{
var req;
if(window.XMLHttpRequest)
req=new XMLHttpRequest();
else if(window.ActiveXObject)
req=new ActiveXObject("Microsoft.XMLHTTP");
else
{
alert("Browser not support");
return false;
}
var strx=jQuery.now();
var querystrx="../B1/barcode.php?str="+strx;
req.open("GET",querystrx,true);
req.send(null);
}
ฟังก์ชั่น encodeing() ก็จะเรียกไฟล์ barcode.php ขึ้นมาทำงาน โดยไฟล์ barcode.php ก็จะสร้าง id ขึ้นมาเป็นตัวเลข 12 หลักแล้วส่งต่อไปยัง php_barcode.php เพื่อนำตัวเลข 12 หลักไปเข้ารหัส แล้วออกมาเป็นตัวเลข 13 หลัก ซึ่งหลักที่ 13 เป็นตัวเช็ค digit หลังจากได้เลข มา 13 หลักแล้ว ผมต้องการให้ไฟล์ php_barcode.php นำเลข13 หลักนั้น ไปเขียนไว้ในไฟล์ id.txt แต่มันไม่ยอมเขียน
barcode.php
Code (PHP)
require("php-barcode.php");
require("../cms/config/connect.php");
$dd=date(d);
$mm=date(m);
$yy=date(Y);
if($con){
$sql="select * from cms_runid";
$query=mysql_query($sql);
$result=mysql_fetch_array($query);
if($result[1]!=$dd){
$sql="update cms_runid set id='0001', day='$dd' where day='$result[1]'";
}
else {
$nid=++$result[0];
$nid=str_pad($nid, 4, "0", STR_PAD_LEFT);
$sql="update cms_runid set id='$nid' where day='$result[1]'";
}
$query=mysql_query($sql);
$sql="select * from cms_runid";
$query=mysql_query($sql);
$result=mysql_fetch_array($query);
$nextid=$result[0];
$nowdate=$dd.'/'.$mm.'/'.$yy;
$rid=$yy.$mm.$dd.$nextid;
}
function getvar($name){
global $_GET, $_POST;
if (isset($_GET[$name])) return $_GET[$name];
else if (isset($_POST[$name])) return $_POST[$name];
else return false;
}
if (get_magic_quotes_gpc()){
$code=stripslashes(getvar('code'));
} else {
$code=getvar('code');
}
if (!$code) $code=$rid;
barcode_print($code,getvar('encoding'),getvar('scale'),getvar('mode'));
php_barcode.php (บางส่วน) เก็บรหัส 13 หลักไว้ในตัวแปร $intcode
Code (PHP)
/* paint the bars */
$width=true;
for ($i=0;$i<strlen($bars);$i++){
$val=strtolower($bars[$i]);
if ($width){
$xpos+=$val*$scale/1.1;
$width=false;
continue;
}
if (ereg("[a-z]", $val)){
/* tall bar */
$val=ord($val)-ord('a')+1;
$h=$height2/3;
} else $h=$height/3;
imagefilledrectangle($im, $xpos, $space['top'], $xpos+($val*$scale)-1, $h, $col_bar);
$xpos+=$val*$scale;
$width=true;
}
/* write out the text */
global $_SERVER;
$intcode="";
$chars=explode(" ", $text);
reset($chars);
while (list($n, $v)=each($chars)){
if (trim($v)){
$inf=explode(":", $v);
$fontsize=$scale*($inf[1]/1.8)/1.4;
$fontheight=($total_y-($fontsize/2.7)+30)/2.8;
@imagettftext($im, $fontsize, 0, $space['left']+($scale*$inf[0])+5,
$fontheight, $col_text, $font_loc, $inf[2]);
$intcode.=$inf[2];
}
}
$pathweb=$_SERVER[DOCUMENT_ROOT];
$pathfile=$pathweb."/cms/id.txt";
$fileid=fopen($pathfile,"w+");
fwrite($fileid,$intcode);
/* output the image */
$mode=strtolower($mode);
if ($mode=='jpg' || $mode=='jpeg'){
header("Content-Type: image/jpeg; name=\"barcode.jpg\"");
imagejpeg($im);
} else if ($mode=='gif'){
header("Content-Type: image/gif; name=\"barcode.gif\"");
imagegif($im);
} else {
header("Content-Type: image/png; name=\"barcode.png\"");
imagepng($im,"../B1/img/bars.png");
}
}
Tag : PHP, MySQL, HTML/CSS, Ajax, jQuery, Windows
|
|
 |
 |
 |
 |
Date :
2012-07-17 10:20:53 |
By :
davilllll |
View :
1511 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |