PHP 板


LINE

看板 PHP  RSS
前幾天才開始學寫網頁的所以觀念不是很好,想來這邊問一下 目標功能: 這是模擬一個使用者介面,用來達到遠端控制遙控車的功能,網頁上會有連續圖片 看到遙控車目前看到的圖片,而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
1F:推 eight0:呃 在瀏覽器按右鍵檢視原始碼大概就知道哪裡不太對了 09/07 19:05
2F:推 characterlu:前幾天才開始寫 可以血這樣喔 09/07 23:57
3F:→ tangent7787:喔我是參考很多code然後都在一起的XD 09/08 10:11
4F:→ tangent7787:一樓大大可以說詳細點嗎 謝謝 我不太會用QQ 09/08 10:29
5F:→ tangent7787:我這樣call function好像根本是錯得.. 09/08 10:57
6F:→ tangent7787:已解決,謝謝! 09/08 14:36







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:BabyMother站內搜尋

TOP