Jump to content

Something simple prolly


supanoob

Recommended Posts

OK, so i recently got myself a host. When i uploaded all my files i keep getting this error:

 

Warning: include_once(/styles/style.css) [function.include-once]: failed to open stream: No such file or directory in /home/bumwarsc/public_html/index.php on line 9

 

Warning: include_once() [function.include]: Failed opening '/styles/style.css' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/bumwarsc/public_html/index.php on line 9

 

I dont know why? I have checked my permissions for the folders etc. Seems ok to me... below is the code used when that error was thrown.

 

<?php 
session_start();
?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
include_once('/styles/style.css');
?>

 

 

Link to comment
Share on other sites

You're not understanding absolute paths, but regardless I think you are not wanting to include a CSS file. Including it would parse the data for PHP, you'd just get a hundred and one errors. You can only link clientside code to other clientside code.

 

Of course you can do this to keep it dynamic:

$stylepath = '/styles/style.css';
print "<link rel='stylesheet' type='text/css' href='$stylepath' />";

 

include

require

include_once

require_once

 

EDIT: stuff added

 

Link to comment
Share on other sites

You're not understanding absolute paths, but regardless I think you are not wanting to include a CSS file. Including it would parse the data for PHP, you'd just get a hundred and one errors. You can only link clientside code to other clientside code, within the <head> tag.

 

The code was working fine on Wamp5 Server when i was working on the site offline. Also when i add the rest of the code to the document, it wont include php files when telling it too aswell, i just end up with a screen full of the same error.

Link to comment
Share on other sites

Your paths are wrong, I'm sure if you used file_exists or realpath on the file it wouldn't be there.

 

Again, You can't include non-PHP files.

 

Ok, so you were right about the file "not being there" however, it is on my server, in the same directory as the index file. I have sorted the CSS and JS files out, so why wont the php files show?

Link to comment
Share on other sites

Why not set a relative path if they're in the same folder? ./style.css. But no, Include/Require_once only executes a file once per execution of PHP, You cannot include anything other than PHP, as that would make no sense, It can only include material to be evaluated.

Link to comment
Share on other sites

Why not set a relative path if they're in the same folder? ./style.css. But no, Include/Require_once only executes a file once per execution of PHP, You cannot include anything other than PHP, as that would make no sense, It can only include material to be evaluated.

 

Yeah i understand that now, and i thought i was doing that, basically i have something like this for my PHP files:

 

if ($_GET['step'] == 'home') {include_once('./home.php');}

 

The file is still not showing though :(

Link to comment
Share on other sites

You can include anything you want. It becomes part of the source the same as if you copy/pasted the contents of the file where the include statement is at. Php code in the included file is denoted by php tags around it, the same as any other php code.

 

While you should use an external .css file and let the browser fetch it, you can do what you are trying and include the .css file as in-line content that is then output on the page.

 

You must use the correct path to the file being included. Your original problem is that a leading slash / on a file path refers to the root of the current hard disk.

Link to comment
Share on other sites

That should work theorietically, Are you one hundred percent sure "home.php" is in the exact same path as the file that's running the code (including) it?

 

Yes i am

 

You can include anything you want. It becomes part of the source the same as if you copy/pasted the contents of the file where the include statement is at. Php code in the included file is denoted by php tags around it, the same as any other php code.

 

While you should use an external .css file and let the browser fetch it, you can do what you are trying and include the .css file as in-line content that is then output on the page.

 

You must use the correct path to the file being included. Your original problem is that a leading slash / on a file path refers to the root of the current hard disk.

 

Im in college at the moment, i shall have a look and get back to you when i get home. Thanks for the help :)

Link to comment
Share on other sites

Again, You can't include non-PHP files.

 

Sure you can

 

include('styles/screen.css');
include('index.html');

 

Throws not a single error and outputs it's contents to screen. The include functions just search for <?php ?> statements and parse those everything else is passed to the internal HTML engine.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.