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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.