PHP require absolute path not working

Website url

Test url: https://zmtechnolog.top/abi.php

My issue

PHP script:

<?php
	require_once "/includes/head_tags.php";
?>

(yes,it is so simple and was only used to test)

This is what my /htdocs/includes folder looks like:

And I’m getting this when visiting the page:

Warning: require_once(/includes/head_tags.php): failed to open stream: No such file or directory in /home/vol19_1/infinityfree.com/if0_34450035/htdocs/abi.php on line 2

Fatal error: require_once(): Failed opening required '/includes/head_tags.php' (include_path='.:/usr/share/pear/') in /home/vol19_1/infinityfree.com/if0_34450035/htdocs/abi.php on line 2

Changing /includes/head_tags.php into /htdocs/includes/head_tags.php didn’t work.

Any ideas of why is this ever happening?
The relative path is indeed working for me without any problem.

Try to use __DIR__."/includes/head_tags.php" as require path and see if it works. __DIR__ references /home/vol19_1/infinityfree.com/if0_34450035/htdocs/ in this case.

5 Likes

Yes it worked.
Thank you for your assistance. :grinning:

(I pretty much believed that this __DIR__ thing shows up nowhere in docs…)

2 Likes

You’re welcome as always :slight_smile:

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.