What should I do if I can write text to an external text file in a php file executed using a command line?

Source: Internet
Author: User
Can I write text to an external text file in the PHP file executed using the command line first in my webroot folder (my files are: C: \ xampp \ htdocs \) create a new folder to put my php file, name it externalIOTest, and then create a log under this path: C: \ xampp \ htdocs \ externalIOTest. t. can I write text to an external text file in the PHP file executed using the command line?
First, create a new folder in my webroot folder (my folder is: C: \ xampp \ htdocs \) to put my php file. name this folder externalIOTest, then, under this path, C: \ xampp \ htdocs \ externalIOTest \

Create a log.txt file, and then create a php file named iotest. php. its content is:

PHP code
  
  


This code is simple. open log.txt and add the current time later.

Execute this php file through Apache in the browser and open the connection: http: // localhost/externalIOTest/iotest. php
Then open log.txt, with the inserted text: 09:22:36

The code is OK.

Open cmd and go to the C: \ xampp \ php \ path,

Run: C: \ xampp \ php> php.exe-q "C: \ xampp \ htdocs \ exterbalIOTest \ iotest. php"

After that, open log.txt, which is not followed by any text.



My question is: how can I write text to an external text file after php.exe is used to execute the php file?

Thank you.




------ Solution --------------------
A long time ago, it was hard to remember how to execute the command line.
It should be a path problem $ fp = fopen ('C: \ xampp \ htdocs \ exterbalIOTest \ log.txt ', 'A + ');
Try it like this.

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.