[請益] 不換頁連續寫檔and PHP傳字串
前幾天才開始學寫網頁的所以觀念不是很好,想來這邊問一下
目標功能:
這是模擬一個使用者介面,用來達到遠端控制遙控車的功能,網頁上會有連續圖片
看到遙控車目前看到的圖片,而button有 前 後 左 右 停 五個按鈕來控制遙控車,
前後左右停五個按鈕每按下一次就會寫入log檔中,而另外有一隻C code的程式用來
讀取這個log檔來達到控制方向的功能
前提:盡量不使用sql(因為這是run在嵌入式開發板上跑的,再移植sqlite怕來不及)
問題:
1.網頁上的按鈕按下後檔案只會寫入一次,
Ex:按下button順序:Stop,Front,Back,Left,Right,Stop,Stop,Stop...
照理說寫入的log檔應該也是Stop,Front,Back,Left,Right,Stop,Stop,Stop...
但檔案卻是Stop,Front,Back,Left,Right 就沒了
不知道是不是因為沒有換頁的原因? 我看別人送跟收都是分成server與client
兩個網頁?可是我的網頁介面不想要讓使用者看起來像是有跳頁的感覺
2.因為我不會傳字串,所以現在code感覺很冗長,明明是一樣的功能只是寫入的字串
不一樣,希望是把現在front,back,left,right,stop濃縮成WriteLog一個function
就好....因為只有差字串XD
先感謝大家看完我的問題Orz
在這裡拜託神手求解.....
=================== source code =======================
<HTML>
<head>
<title>ThirdEye-System</title>
<?php
/*function WriteLog(){
$myFile = "Drive.log";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Front.\n";
//$stringData = $_POST['direction'];
fwrite($fh, $stringData);
fclose($fh);
}*/
function front(){
$myFile = "Drive.log";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Front.\n";
//$stringData = $_POST['direction'];
fwrite($fh, $stringData);
fclose($fh);
}
function back(){
$myFile = "Drive.log";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Back.\n";
//$stringData = $_POST['direction'];
fwrite($fh, $stringData);
fclose($fh);
}
function left(){
$myFile = "Drive.log";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Left.\n";
//$stringData = $_POST['direction'];
fwrite($fh, $stringData);
fclose($fh);
}
function right(){
$myFile = "Drive.log";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Right.\n";
//$stringData = $_POST['direction'];
fwrite($fh, $stringData);
fclose($fh);
}
function stop(){
$myFile = "Drive.log";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Stop.\n";
//$stringData = $_POST['direction'];
fwrite($fh, $stringData);
fclose($fh);
}
?>
</head>
<body>
<H1>Welcome to ThirdEye System</H1>
<canvas id="cvs" width="700" height="540">[No canvas support]</canvas>
<script>
var serverAddress = "snap.jpg";
var counter=0;
function drawPicCanvas(){
var ctx = document.getElementById('cvs').getContext('2d');
ctx.clearRect (0, 480, 300, 510);
var img = new Image();
img.onload = function(){
ctx.drawImage(img,0,0);
//ctx.beginPath();
//ctx.moveTo(30,96);
//ctx.lineTo(70,66);
//ctx.lineTo(103,76);
//ctx.lineTo(170,15);
//ctx.stroke();
};
img.src= "snap.jpg?"+ new Date().getTime();
ctx.font = 'bold 30px sans-serif';
ctx.textBaseline = 'top';
ctx.strokeText('Image No.'+counter, 0, 480);
counter++;
setTimeout(drawPicCanvas,1000);
}
drawPicCanvas();
</script>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
<! stop >
<div style="top :380px; left : 580px; position : absolute;"
id="StopButton">
<button type="button"style="height: 70px; width: 140px"
onClick="<?php stop() ?>">
<font size=20 color="#0000FF">Stop</font>
</button>
</div>
<! go forward >
<div style="top :310px; left : 580px; position : absolute;"
id="FrontButton">
<button type="button"style="height: 70px; width: 140px"
onClick="<?php front() ?>">
<font size=20 color="#0000FF">Front</font>
</button>
</div>
<! go back >
<div style="top :450px; left : 580px; position : absolute;"
id="BackButton">
<button type="button"style="height: 70px; width: 140px"
onClick="<?php back() ?>">
<font size=20 color="#0000FF">Back</font>
</button>
</div>
<! turn left >
<div style="top :380px; left : 440px; position : absolute;"
id="LeftButton">
<button type="button"style="height: 70px; width: 140px"
onClick="<?php left() ?>">
<font size=20 color="#0000FF">Left</font>
</button>
</div>
<! turn right >
<div style="top :380px; left : 720px; position : absolute;"
id="RightButton">
<button type="button"style="height: 70px; width: 140px"
onClick="<?php right() ?>">
<font size=20 color="#0000FF">Right</font>
</button>
</div>
</form>
</body>
</HTML>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.243.171.65
推
09/07 19:05, , 1F
09/07 19:05, 1F
推
09/07 23:57, , 2F
09/07 23:57, 2F
→
09/08 10:11, , 3F
09/08 10:11, 3F
→
09/08 10:29, , 4F
09/08 10:29, 4F
→
09/08 10:57, , 5F
09/08 10:57, 5F
→
09/08 14:36, , 6F
09/08 14:36, 6F