supanoob Posted April 23, 2010 Share Posted April 23, 2010 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/199467-something-simple-prolly/ Share on other sites More sharing options...
oni-kun Posted April 23, 2010 Share Posted April 23, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/199467-something-simple-prolly/#findComment-1046891 Share on other sites More sharing options...
supanoob Posted April 23, 2010 Author Share Posted April 23, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/199467-something-simple-prolly/#findComment-1046892 Share on other sites More sharing options...
oni-kun Posted April 23, 2010 Share Posted April 23, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/199467-something-simple-prolly/#findComment-1046893 Share on other sites More sharing options...
supanoob Posted April 23, 2010 Author Share Posted April 23, 2010 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. its been a while since i coded but when i used too i used to be able to use include_once(); for all files, CSS everything. Quote Link to comment https://forums.phpfreaks.com/topic/199467-something-simple-prolly/#findComment-1046901 Share on other sites More sharing options...
supanoob Posted April 23, 2010 Author Share Posted April 23, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/199467-something-simple-prolly/#findComment-1046908 Share on other sites More sharing options...
oni-kun Posted April 23, 2010 Share Posted April 23, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/199467-something-simple-prolly/#findComment-1046912 Share on other sites More sharing options...
supanoob Posted April 23, 2010 Author Share Posted April 23, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/199467-something-simple-prolly/#findComment-1046998 Share on other sites More sharing options...
oni-kun Posted April 23, 2010 Share Posted April 23, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/199467-something-simple-prolly/#findComment-1047003 Share on other sites More sharing options...
PFMaBiSmAd Posted April 23, 2010 Share Posted April 23, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/199467-something-simple-prolly/#findComment-1047011 Share on other sites More sharing options...
supanoob Posted April 23, 2010 Author Share Posted April 23, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/199467-something-simple-prolly/#findComment-1047015 Share on other sites More sharing options...
ignace Posted April 23, 2010 Share Posted April 23, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/199467-something-simple-prolly/#findComment-1047339 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.