PHP寫檔案--將使用者提交的資料儲存到伺服器的檔案中

來源:互聯網
上載者:User
首先編寫html頁面:

        訂單頁面

Jason的購物清單



再用PHP編寫伺服器端指令檔processorder.php

        訂單結果

Jason的購物車

訂單結果

訂單提交中時間:'.$date.'

'; echo '

您的具體購物清單是:

'; //擷取商品總數量 $total_qty=0; $total_qty=$cloths+$shoes+$glasses; echo '商品總數量:'.$total_qty.'
'; if($total_qty==0){ echo '您沒有購買任何商品!'; }else{ if($cloths>0){ echo $cloths.'件男裝
'; } if($shoes>0){ echo $shoes.'雙鞋子
'; } if($glasses>0){ echo $glasses.'副眼鏡
'; } } //擷取商品總價 $total_amount=0.00; const CLOTHS_PRICE=100; const SHOES_PRICE=300; const GLASSES_PRICE=28; $total_amount=$cloths*CLOTHS_PRICE+$shoes*SHOES_PRICE+$glasses*GLASSES_PRICE; $total_amount=number_format($total_amount,2,'.',' '); echo '

商品總價:¥'.$total_amount.'

'; echo '

收貨地址:'.$address.'

'; //設定檔案輸出內容和格式 $out_put_string=$date."\t".$cloths."件男裝\t".$shoes."雙鞋子\t".$glasses."副眼鏡\t\總價:¥".$total_amount." 收貨地址:\t".$address."\n"; //開啟檔案,(追加模式+二進位模式) @$fp=fopen("$DOCUMENT_ROOT/L02/files/orders.text",'ab'); flock($fp,LOCK_EX); if(!$fp){ echo "

您的訂單沒有提交完成,請再試一次。

"; exit; } //將資料寫入到檔案 fwrite($fp,$out_put_string,strlen($out_put_string)); flock($fp,LOCK_UN); //關閉檔案流 fclose($fp); echo "

資料儲存完成

";?>

最後在files檔案下產生orders.txt檔案, 檔案內容為(可追加):





著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.