php_nub_qq
php_nub_qq

Reputation: 16017

php include path issue

Although this has been asked a thousand times I still managed to screw things up and not find an answer that serves my issue..

I have 2 files

C:\xampp\htdocs\MF\Pages\ads.php
C:\xampp\htdocs\MF\Pages\ads_view.php

I wanna include ads_view from ads what I do is

echo __DIR__;
var_dump(file_exists('ads_view.php'));

and what I get is

C:\xampp\htdocs\MF\Pages
bool(false)

Why can't I include this file when __DIR__ clearly states i'm in the parent folder? ads.php is also included from another file, if that makes any difference?

Upvotes: 0

Views: 155

Answers (2)

Rik
Rik

Reputation: 2032

You can also use the DOCUMENT_ROOT variable in $_SERVER for portability.

var_dump(file_exists($_SERVER['DOCUMENT_ROOT'] . '\MF\Pages\ads_view.php'));

and

include $_SERVER['DOCUMENT_ROOT'] . '\MF\Pages\ads_view.php';

Upvotes: 1

meda
meda

Reputation: 45490

Please put the full path it should work

var_dump(file_exists('C:\xampp\htdocs\MF\Pages\ads_view.php'));

see documentation for file_exists

Upvotes: 1

Related Questions