I use this to include some file
require_once realpath(__DIR__) . '/../anotherfolder2/anotherfolder3/filename2.php
But for some reasons it seems that /.. is ignored and it triggers
Failed opening required '/var/domains/domain.com/foldername1/anotherfolder2/anotherfolder3/filename.php in /var/domains/domain.com/foldername1/anotherfolder2/filename1.php on line 10`
where realpath(DIR) = /var/domains/domain.com/foldername1
What could cause /.. to be ignored, is that something new in php 7.4?
Try to pass the whole path to realpath() function:
require_once realpath(__DIR__ . '/../anotherfolder2/anotherfolder3/filename2.php)
This function changes the
dir1/dir2/../file1
intodir1/file1
. In your case:/var/domains/domain.com/foldername1/../anotherfolder2/anotherfolder3/filename.php
into/var/domains/domain.com/anotherfolder2/anotherfolder3/filename.php
.From documentation:
https://www.php.net/manual/en/function.realpath.php