PHP files executed with the command line can not write text to an external text file, how to handle

Source: Internet
Author: User
PHP files executed with the command line can write text to an external text file
First in my Webroot folder (my is: C:\xampp\htdocs\) Create a new folder to put my php file, give this folder name: Externaliotest, and then under this path, namely: C:\xampp\htdocs\ Externaliotest\

Create a Log.txt file, and then create a php file named iotest.php with the following contents:

PHP Code
  
   
  
   


What this code does is simple: Open the Log.txt and add the current time to the back.

Execute this php file from within the browser via Apache, open connection: http://localhost/externalIOTest/iotest.php
Then open Log.txt, where the text was inserted: 2012-02-06 09:22:36

This shows the code OK.

Then open cmd, go to the C:\xampp\php\ path,

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

After that, the Log.txt is opened and no text is added to the back.



My question is: how can I do this by Php.exe execute PHP files can also write text to external text files?

Thank you.




------Solution--------------------
It was a long time ago with command-line execution.
Should be the path problem $fp = fopen (' C:\xampp\htdocs\exterbalIOTest\log.txt ', ' A + ');
Try it this way.
  • 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.