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.