Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shivamyadav's avatar

php file structure?

Hello, I want to get or choose the right way or right path to require/include a file .. my project directory structure is here . project/forms/student/create.php and i want to add a file in the create.php from the directory structure this project/dbConnection.php.. how can i add a file in it form this path?

0 likes
3 replies
tykus's avatar

I assume you don't have a PHP entry point, e.g. an index.php file that will allow you to define a helper functions file for all requests? So, in that case, relatively referencing the database connection script would be handled like this:

// project/forms/student/create.php
<?php
require(__DIR__ . '/../../dbConnection.php');
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@Shivamyadav always use absolute urls for assets

<link rel="stylesheet" href="/css/style.css">  

Please or to participate in this conversation.