Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP fileexists 1

Status
Not open for further replies.

scriggs

IS-IT--Management
Jun 1, 2004
286
GB
I have some PHP coding which simply makes a path and includes a text file:

Code:
// Variables $host and $folderPath are included in index pages and taken from varDefs.php4
if(!($_GET)) {
$p = "home";
}
else {
$p = $_GET["p"];
}  
$filename_left = '[URL unfurl="true"]http://'.$host.$folderPath.'/inc/'.$p.'/left.inc.php';[/URL]
$filename_testimonials = '[URL unfurl="true"]http://'.$host.$folderPath.'/inc/'.$p.'/testimonials.js';[/URL]
$filename_right = '[URL unfurl="true"]http://'.$host.$folderPath.'/inc/'.$p.'/right.inc.php';[/URL]

Called by
Code:
<?echo '<a href="[URL unfurl="true"]http://'.$host.$folderPath.'?p=home">Home[/URL] Page</a>' ?>

Processed by
Code:
include($filename_right);

I wanted to put some error handling, should a page not exist, but this doesn't work. I get my error message for the file not existing. But it does...
Code:
if (file_exists($filename_left)) {
include($filename_left);
} else {
echo "There has been an error. Click here to inform the webmaster.";
}

I am using PHP 5 on Apache Server on a Windows machine....
 
have you got the directive
Code:
allow_url_fopen = On
set in your php.ini file? you are addressing the file as a url rather than a file so you need this.
 
OK, the ini is controlled by my ISP. So I should address the file instead yeah.

How would i reference the file on the ISP web server?

the root directory is web server??/diff/inc/home/left.inc.php

Thanks...
 
How would i reference the file on the ISP web server?

either quote the absolute path to the document or a relative path. whichever takes your fancy.

Code:
file_exists("/diff/inc/home/left.inc.php"); //eg
// or for relative
file_exists("inc/$p/left.inc.php");

or you may be able to change your isp configuration by shoving a php.ini file into the directory from which you are running the script. you don't need an entire ini file - you could just include the allow_url directive. this only works if the webserver is using cgi (and even then only sometimes).
 
Thanks, that's great. I used the path as you suggested and it works. Have a star!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top