L
L
littleguga2015-07-17 07:58:26
PHP
littleguga, 2015-07-17 07:58:26

How to avoid prescribing full paths?

There is a test.php script:

<?php 
file_put_contents("/home/user/www/t.txt","test\r\n"); ?>

In crontab:
#* * * * * /usr/bin/php /home/user/www/test.php >> /home/user/www/t.l 2>&1

Everything is fine, test is written to the t.txt file.
If the script is test.php, replace with:
<?php
file_put_contents("t.txt","test\r\n"); ?>

It doesn't write anything. How to make it write to a t.txt file without specifying an absolute path?
Thanks in advance for your reply!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-07-17
@littleguga

does not write anything

It writes like that, you just don’t know which directory :)
The absolute path is still needed, but it’s easy to get it via __DIR__ :
Now the file will be saved to the same directory where the script is located.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question