0

I'm running a Gulp 4 / Webpack 4 project using gulp-connect-php and out of nowhere I'm getting errors for all my includes... but... the files are still serving fine locally with no PHP errors in the view.

These two error lines for each and every include when I run npm start:

[Tue Mar 19 20:30:38 2019] PHP Warning: include(svgs/logo_aeg.php): failed to open stream: No such file or directory in E:\Sites\proj\html\web\includes\menus.php on line 13 [Tue Mar 19 20:30:38 2019] PHP Warning: include(): Failed opening 'svgs/logo_aeg.php' for inclusion (include_path='.;C:\php\pear') in E:\Sites\proj\html\web\includes\menus.php on line 13

The way I'm including is this (though I've tried every relative and absolute version, even placing a define root in a config.php file):

<?php include $_SERVER["DOCUMENT_ROOT"] . '/includes/include_file.php' ?>

I've done nothing that I know of except try to install (unrelated) openSSL. This is a Windows 10 machine and it's been working fine. I haven't done an yarn upgrade or otherwise changed my config so I'm stumped.

I'm also not a PHP expert so I could be making a dumb mistake.

Kirk Ross
  • 6,413
  • 13
  • 61
  • 104
  • Tried using a relative path from the current script, eg `include __DIR__ . '/relative/path/to/include_file.php';`? – Phil Mar 20 '19 at 03:49
  • Could you please provide more accurate error messages? What you have above looks like you're trying to include `include_file.php` from within itself, which is generally a really bad idea – Phil Mar 20 '19 at 03:52
  • I'm not trying to include a file from within itself, the files *are* being included even though my terminal is throwing 'no such file' errors. I'll paste the whole error. Could this be a gulp-connect-php issue? – Kirk Ross Mar 20 '19 at 04:47
  • Could be, it depends on what directory it's using as the document root. I definitely recommend **not** using any environment variable such as `$_SERVER` when producing file paths (see my first comment) – Phil Mar 20 '19 at 04:49
  • Thanks @Phil -- I am short on my PHP skills. If it was using the wrong document directory for the root, wouldn't the files not get included and not get served to the browser? So, `` – Kirk Ross Mar 20 '19 at 05:01
  • There's no enough information here for me to answer. You could however debug the value of `$_SERVER['DOCUMENT_ROOT']`, eg `var_dump($_SERVER['DOCUMENT_ROOT']); exit;` – Phil Mar 20 '19 at 05:06
  • It would be `__DIR__ . '/../../relative/path'`. `__DIR__` resolves to a directory, it won't include a trailing-slash so your relative path would need to start with one – Phil Mar 20 '19 at 05:07
  • The output of var_dump($_SERVER['DOCUMENT_ROOT']); exit; is indeed the webroot without a trailing slash. Usually when there is a path error, you see a white screen with the php errors. In this case there are no browser errors and everything appears fine. It is only in my gitbash that I'm seeing the warnings. I'm using a config file to define ROOT now and including that at the top of each file, then the includes are this for any include in any directory: ` – Kirk Ross Mar 20 '19 at 06:10

0 Answers0