Jump to content

Do file* functions accept full directory-paths?


Goldeneye

Recommended Posts

I have a templating system that I'm currently using:

(This is the only relevant (to my problem) function)

<?php
class template {
	var $page;

	function page($template){
		if(file_exists($template)) $this->page = join('', file($template));
		else exit('"'.$template.'" could not be found.');
  		}
}
$layout = new template;
?>

 

This is essentially how I'm trying to use it.

 

<?php
define('sp', 'http://foobar.com/generic/'); //Path to the PHP-Scripts
define('tp', sp.'templates/'); //The Path to the directory that contains the template-directories.
$_SESSION['path'] = 'style_42'; //This comes from a database field that the use can change.
$layout->page(tp.$_SESSION['path'].'login.html');
?>

 

I thought this code would work, but when I tried it, I got the "http://foobar.com/generic/templates/style_42/login.html" could not be found (as returned by the $layout->page() function. The path is valid (if you copy/paste it into the address-bar and view it, the HTML-File does show up. The file_exists() function says otherwise, though.

 

Is There a reason or solution for this? Does anyone have any suggestions?

 

A preemptive thanks.

There's some stuff in php.ini that controls whether or not PHP will open files given as URLs, so you might look into that.

 

Otherwise full paths work, for example:

c:\a\path\to\this\file.txt

/home/users/joeboo/myfile.txt

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.