1

This is a longshot but I have a file with something like this:

document structure: /some/path/start.php

<?php
require_once '../../another/path/test.php';
?>

and

/another/path/test.php /another/path/images/

<?php 
test.php
hello<img src='images/1.jpg'>
?>

I'm looking for a way for the required file (test.php) to correctly load the images (essentially reset what it believes to be the currrent directory). I don't want to force people to use absolue paths and really don't want to add some variable in there. Is there a php construct to handle this? I'm using Zend_Framework. Maybe the reverse, a construct to have multiple index.php files that map via absolute paths to my starter script for Zend Framework.

Any ideas would be appreciated? I have the following there's an elegant sol'n - I'm just not seeing it.

timpone
  • 19,235
  • 36
  • 121
  • 211

2 Answers2

6

I always use:

require_once(dirname(__FILE__).'/path/to/other/script/relative/to/this/file.php');

Or in your case:

require_once(dirname(__FILE__).'../../another/path/test.php');

That way you're sure you're including from relative to the file you're editing.

Josh
  • 10,961
  • 11
  • 65
  • 108
0

I'm not sure if I understand you correctly - forgive me if I don't - but I think you are mistaken about the relationship between includes and the resulting HTML document. All links in a HTML document are relative to its URL. Whether the URLs are output from within an include or not, and which this include resides in, is totally irrelevant.

You will probably have to find out your current web root, and output the image links relative to that.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • yeah, thinking of some possible workaround - I could symlink in to the directory or manage paths at the mod_rewrite level but those seem a little cumbersome. maybe use jquery, and set all img variable within a specific container to their absolute counterparts if they are relative. – timpone Mar 05 '10 at 23:41