1

I have a few files in a directory, let’s say, named includes on my GoDaddy web server. The directory contains the files which have the snippets that get repeated in every file on the web server. Instead of manually including those snippets in every file, I want the server to read those files from that directory and include in the .htm that it’s about to send to the client.

I am able to include those files in the .htm files that are placed in the root directory of the server. However, when the directory changes, I do not know how to get the complete path relative to the current directory. Can anybody help me with resolving this matter. I want to include those files into a file that is located in posts/language/ directory.

I am using the following PHP command to include the files:

<?php  include ("includes/scripts-and-style.htm"); ?>

I would like to add that it’s working for the file in the base folder. When the files move into the subdirectory, the server fails to find page_includes folder.

Irfan
  • 214
  • 1
  • 4
  • 1
    Does this answer help you : https://stackoverflow.com/a/22912261/2666094 ? – Opsse May 21 '18 at 16:53
  • I will let you know after testing the code. Many thanks for taking the time to find what appears to be a correct answer, many thanks. – Irfan May 21 '18 at 16:56
  • `getcwd()` could be established in a functions file located in the root of the server which could then be `required()` and used as a method, ie `function getRootDir() { return getcwd(); }` – Jaquarh May 21 '18 at 16:56
  • @Opsse I have tested the code provided in the answer marked as correct in that thread, and it works for me as well. Many thanks for taking the time; I truly appreciate it. – Irfan May 21 '18 at 17:19
  • Possible duplicate of [PHP include absolute path](https://stackoverflow.com/questions/22912121/php-include-absolute-path) – Opsse May 21 '18 at 17:20
  • @Opsse In my opinion, it actually is a duplicate, not just a possible duplicate. I do not know the procedure; as far as I’m concerned, you can mark it as a duplicate. – Irfan May 22 '18 at 13:57
  • @Irfan I can't set it as duplicate myself, I flagged it as possible duplicate now it's in pending for peer validation – Opsse May 22 '18 at 14:06
  • @Opsse O.K. Thank you, once again. – Irfan May 22 '18 at 14:07

0 Answers0