Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

including other files into a php file

Thread Tools
 
Search this Thread
 
Old 19 March 2003, 11:51 AM
  #1  
gregh
Scooby Regular
Thread Starter
 
gregh's Avatar
 
Join Date: Dec 1999
Posts: 3,360
Likes: 0
Received 0 Likes on 0 Posts
Post

I had my index.htm working fine, but for various reasons I need it to be php.

However when I make it php, my includes don't work.

for example:

<?php
include '/php/text_rotator.php';
?>

doesn't work, it gives me an error:

Warning: Failed opening '../php/text_rotator.php' for inclusion (include_path='.:') in /usr/local/etc/httpd/vhosts/gregh.co.uk/ipaqsoft/index.php on line 48

however under the .htm version, this worked fine:

<!--#include virtual="/php/text_rotator.php"-->

any ideas?

thanks,

greg
Old 19 March 2003, 12:00 PM
  #2  
stevencotton
Scooby Regular
 
stevencotton's Avatar
 
Join Date: Jan 2001
Location: behind twin turbos
Posts: 2,710
Likes: 0
Received 1 Like on 1 Post
Post

Hello again

The HTML version you were using is SSI, that's an Apacheism unrelated to HTML. SSI's 'virtual' directive will mean include the file relative to DocumentRoot, which is specified in your httpd.conf. Looks as if the PHP search path contains the CWD only (assuming the colon is a seperator), so you need to check the path that PHP is searching. I don't know the faintest thing about PHP though

Steve.
Old 19 March 2003, 12:13 PM
  #3  
Andrewza
Scooby Regular
 
Andrewza's Avatar
 
Join Date: Jan 2002
Posts: 667
Likes: 0
Received 0 Likes on 0 Posts
Post

assuming /php/ is in your document root
<?
include("{$_SERVER["DOCUMENT_ROOT"]}/php/text_rotator.php");
?>

php will search the current directory by default, but you can just use the pre-defined document root variable to pull things and have it just work

Old 19 March 2003, 09:51 PM
  #4  
ripmaze
Scooby Regular
 
ripmaze's Avatar
 
Join Date: Aug 2002
Posts: 135
Likes: 0
Received 0 Likes on 0 Posts
Post

If you have an older version of PHP (pre 4.1.0 I think) you have to use just $DOCUMENT_ROOT instead of $_SERVER["DOCUMENT_ROOT"]:

include($DOCUMENT_ROOT . '/php/text_rotator.php');

Regardless of which you use, you might find the document root already has a trailing slash from the Apache set-up.

Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
psport
Subaru Parts
3
04 October 2015 07:35 PM
Nick_Cat
Computer & Technology Related
2
26 September 2015 08:00 AM
Littleted
Computer & Technology Related
0
25 September 2015 08:44 AM



Quick Reply: including other files into a php file



All times are GMT +1. The time now is 04:20 AM.