S
S
Shlyahten2018-06-06 17:41:20
PHP
Shlyahten, 2018-06-06 17:41:20

Why is cron executing php at the root?

This problem is more of an aesthetic one.
The hosting has a file in the /www/example.ru/dir/index.php directory.
I run the following command in the hosting crown:
php -f /var/www/vh12345/data/www/example.ru/dir/index.php
Everything works well, but the problem is that the files that the script writes (there txt and jpg) are created in the root directory: /var/www/vh12345/data/
If you do not run through cron, then everything is fine and the files are created in the script directory . How could this be corrected?
Sample code for a file:

if (!copy($pic_file, "picture.jpg")) {
    echo "не удалось скопировать $pic_file...\n";
}

Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shlyahten, 2018-06-06
@Shlyahten

I found this code, it might help:

$path_parts = pathinfo($_SERVER['SCRIPT_FILENAME']); // определяем директорию скрипта
chdir($path_parts['dirname']); // задаем директорию выполнение скрипта

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question