1

I have a project with so many php includes and requires , when i downloaded all the file from the server to my localhost , the pages where not loading correctly , i found out it was because of the path in include and require funtions

when i gave in my view file

require 'models/topic_db.php';

its working correctly but my folder is actually like this admin/models/topic_db.php and in my view file is at admin/views/topic.php

and in my server it works like this

require '../models/topic_db.php';

I dont understand what the issue is , but all the pages are having similar issue so i can't go to each page and fix it , so i need a common solution , is there a way i can fix it without editing each and every file ?

for the record this is also working require(dirname(__DIR__).'/models/topic_db.php');

But in all my codes the format is like this require '../models/topic_db.php';

Any way i can fix it using .htaccess ?

Right now my .htaccess looks like this

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.php$ index.php [NC]

And my project is at

C:\xampp\htdocs\live\project

Image to get an idea of the folder path

<?php

session_start();
//include ('../../config.php');
include(dirname(__DIR__).'../config.php');

require_once(dirname(__DIR__).'../system/core/coreModel.php');
//require_once '../../system/core/coreModel.php';
$db = new coreModel();
$conn = $db->connectDb();
?>
Tetalks
  • 13
  • 5
  • Create a Virtual Host for your site to run in that matches the directory structure on you LIVE site. Running out of `locahost/folder` is not the same structure as your live site – RiggsFolly Mar 21 '18 at 11:46
  • i am using xampp to run this php project – Tetalks Mar 21 '18 at 11:46
  • check your DocumentRoot , make certain your local web server points to the same place as the server. – YvesLeBorg Mar 21 '18 at 11:49
  • In my server it is /var/www/html and inside it has this admin folder – Tetalks Mar 21 '18 at 11:50
  • Is ur localhost runs on windows and server is is linux? – Shashikala Mar 21 '18 at 11:52
  • yes my localhost run on windows and server is in linux – Tetalks Mar 21 '18 at 11:53
  • https://stackoverflow.com/questions/4178263/make-a-path-work-both-on-linux-and-windows ....See this...they both treat path differently...So better to change the path as given in the answer.. Also refer this https://stackoverflow.com/questions/11604445/php-absolute-path-to-root – Shashikala Mar 21 '18 at 11:55
  • Let me check any other way you know that of? – Tetalks Mar 21 '18 at 11:57

1 Answers1

0

Why it is working In Server because there is two dots in :

require '../models/topic_db.php'; 

which denotes one folder inside.It should be as :

require 'models/topic_db.php'; 
Ankit Mishra
  • 130
  • 11