: This article mainly introduces PHP file writing-saving the data submitted by users to files on the server. For more information about PHP tutorials, see. First, write the html page:
Order pageJason's shopping list
Use PHP to write the server-side script file processorder. php
Order resultJason's shopping cart order result
Order submission time: '. $ date .''; Echo'Your specific shopping list is:
'; // Obtain the total number of items $ total_qty = 0; $ total_qty = $ cloths + $ shoes + $ glas; echo' total number of items: '. $ total_qty .'
'; If ($ total_qty = 0) {echo' you have not purchased any products! ';} Else {if ($ cloths> 0) {echo $ cloths.' men's wear
';} If ($ shoes> 0) {echo $ shoes.' pair of shoes
';} If ($ glasses> 0) {echo $ glasses.' pair glasses
';}} // Get the total price of the product $ 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 Price: ¥ '. $ total_amount .'
'; Echo'Shipping address: '. $ address .'
'; // Set the file output content and format $ out_put_string = $ date. "\ t ". $ cloths. "Men's wear \ t ". $ shoes. "Pair of Shoes \ t ". $ glasses. "pair glasses \ t \ Total Price: ¥ ". $ total_amount. "Shipping Address: \ t ". $ address. "\ n"; // open the file (append mode + binary mode) @ $ fp = fopen ("$ DOCUMENT_ROOT/L02/files/orders. text ", 'AB'); flock ($ fp, LOCK_EX); if (! $ Fp) {echo"Your order has not been submitted. please try again.
"; Exit;} // write data to the file fwrite ($ fp, $ out_put_string, strlen ($ out_put_string); flock ($ fp, LOCK_UN ); // close the file stream fclose ($ fp); echo"Data saved
";?>
Finally, the orders.txt file is generated under the files File. the file content is (appendable ):
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above introduces PHP writing files-saving the data submitted by users to the files on the server, including some content, and hope to be helpful to friends who are interested in PHP tutorials.