php require_once geçerli çalışma dizini sıfırlama

2 Cevap

Bu longshot ama ben böyle bir şey ile bir dosya var:

document structure: /some/path/start.php

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

ve

/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 vereally 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.

Herhangi bir fikir mutluluk duyacağız? Ben zarif bir sol'n var şu var - Ben sadece göremiyorum.

2 Cevap

Ben her zaman kullanın:

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

Ya da senin durumunda:

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

Bu şekilde size düzenlediğiniz dosyasına göre de dahil olmak üzere emin misin.

Ben seni doğru anladıysam eğer emin değilim - Ben yapmazsam beni affet - ama içerir ve elde edilen HTML belge arasındaki ilişki hakkında yanlış olduğunu düşünüyorum. Bir HTML belgesi olarak tüm bağlantılar vardır relative to its URL. URL'ler include veya içinde çıktı, ve bu Oturuyor dahil olan olsun, tamamen alakasız.

Muhtemelen sizin şimdiki web kök bulmak zorunda, ve bu çıkış göreceli görüntü bağlantıları olacaktır.