2 Replies - 606 Views - Last Post: 14 August 2012 - 12:43 PM Rate Topic: -----

#1 codabra  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-August 12

PHP include from a different directory.

Posted 13 August 2012 - 10:27 PM

Bascially what I'm trying to do is include a .js file (php include file), in a php include() file and more importantly have it work in every file.

Here is the basic structure

-Website

Index.php

- Inner<---- has 3 sub folders


one<--- each sub folder has at least one other

onetwo

file.js


two<-sub folder

twotwo

twothree

include.php <--- a file that appears on all pages. I would like to include another file to php include() and include file.js


three<- sub folder

threetwo

file.php


Things I've tried.
Putting the actual script in the include.php using script tags, but it only worked on that one page. To be a bit more clear, this is for a navigation.

I've also tried
<?php include($_SERVER['DOCUMENT_ROOT'].'./one/onetwo/file.js'); ?>


<?php include(/one/onetwo/file.js); ?>


I've even tried to use php include(_dir_)..but i think i used that wrong. I've tried ever possible combination so i'm thinking maybe its something else or another way. Not sure what i'm doing wrong.

I have managed not to get a warning on occasion in testing but it seems to just print out in text the actual script ... which i'd be okay with if the navigation actually worked.


$(document).ready(setDropDown);
function setDropDown(){
	$("#navigation li").hover(function() {
		var timeout = $(this).data("timeout");
		if(timeout) clearTimeout(timeout);
		$(this).children("ul").slideDown(350, function(){
			
			$(this).parent().addClass('activeList')
		})
	}, function() {
		
		$(this).data("timeout", setTimeout($.proxy(function() {
			$(this).children("ul").slideUp(200, function(){
				
				$(this).parent().removeClass('activeList')
			})
		}, this), 300)); 
	});
}


Is This A Good Question/Topic? 0
  • +

Replies To: PHP include from a different directory.

#2 Tayacan  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • Posts: 275
  • Joined: 18-January 11

Re: PHP include from a different directory.

Posted 14 August 2012 - 02:34 AM

Nuh uh, you can't include javascript straight from PHP - include() is meant to include other PHP files. In order to include a .js file, you'd need to do something like this:

<script type="text/javascript" src="path/to/js/file.js"></script>



You can write it directly as html, or echo it from PHP - just make sure you don't mess up the quotes.
Was This Post Helpful? 1
  • +
  • -

#3 codabra  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-August 12

Re: PHP include from a different directory.

Posted 14 August 2012 - 12:43 PM

Thank You :bananaman:
Wow... who knew the answer was so simple. I was racking my brain for a day over this one code!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1