Failed to open stream

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Failed to open stream

Postby Alt789 » 23. June 2023 14:16

Hi, I must be doing something stupid because I keep getting this message:

Warning: include(localhost/mywebsite/styles/mainstyles.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\mywebsite\index.php on line 8

Warning: include(): Failed opening 'localhost/mywebsite/styles/mainstyles.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\mywebsite\index.php on line 8

Can anyone tell me what I'm doing wrong? I'm just trying to include a stylesheet.

My website code is simply:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html>
</head>

<body>

<?php include "localhost/mywebsite/styles/mainstyles.php"; ?>

</body>
</html>
Alt789
 
Posts: 2
Joined: 23. June 2023 14:06
XAMPP version: 8.1.6
Operating System: Windows 11

Re: Failed to open stream

Postby Nobbie » 24. June 2023 11:13

Indeed, thats a wrong path. Do not include the servername, only the path. As your index.php runs in mywebsite, ommit that folder also:

include "styles/mainstyles.php";
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04

Re: Failed to open stream

Postby Alt789 » 25. June 2023 03:43

Nobbie wrote:Indeed, thats a wrong path. Do not include the servername, only the path. As your index.php runs in mywebsite, ommit that folder also:

include "styles/mainstyles.php";


Thanks a lot. That worked! Thanks a lot!

One final thing. I can see that I can add "../" when referencing the same stylesheet from another directory, but is there a way to do that using an absolute path, as opposed to the relative ../ ?
Alt789
 
Posts: 2
Joined: 23. June 2023 14:06
XAMPP version: 8.1.6
Operating System: Windows 11

Re: Failed to open stream

Postby Nobbie » 25. June 2023 11:37

Of course, simply apply the full pathname c:/xampp/htdocs/mywebsite/styles/mainstyles.php

But keep in mind that absolute pathnames may not work on other servers (if you upload your script to a webhoster), as they probably have a different structure, i.e. mostly running Linux, which even does not know drive letters. You should use relative pathnames mostly until you definately need absolute pathnames.
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 202 guests