PHP file writing-save the data submitted by the user to the file on the server

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.