Jump to content

file_exists() error


pcbytes

Recommended Posts

ok So I am trying to create a navbar on my website so it will show a "previous" and "next" link based on where I am... so far my variables are filling out with the right info... but when i use file_exists($prev_full) it doesnt return the link... here is my code you can see... as well as the debug values of the variables.. please let me know what im doing wrong and how i can correct it. thank you!

 


<?php
$page = $_GET['page'];
urlencode($page);
if($page > "")

{
include($page);

$base_url = 'http://' .$_SERVER['HTTP_HOST'];
$full_path = $_GET['page'];
$base = dirname($full_path);
$page_file = basename($full_path);
$page_num = substr($page_file
, strrpos($page_file, "_") + 1
, strpos($page_file, ".php") - strrpos($page_file, "_") - 1
);

$partial_path = substr($page_file, 0, strrpos($page_file, "_"));

print "<p>base_url=[$base_url]</p>\n";
print "<p>full_path=[$full_path]</p>\n";
print "<p>base=[$base]</p>\n";
print "<p>page_file=[$page_file]</p>\n";
print "<p>page_num=[$page_num]</p>\n";
print "<p>partial_path=[$partial_path]</p>\n";

$prev_page_file = $partial_path . "_" . (string)($page_num-1) . ".php";
$next_page_file = $partial_path . "_" . (string)($page_num+1) . ".php";

print "<p>prev_page_file=[$prev_page_file]</p>\n";
print "<p>next_page_file=[$next_page_file]</p>\n";

$prev_full = "/" . $base . "/" . $prev_page_file;
$next_full = "/" . $base . "/" . $next_page_file;
print "<p>$prev_full</p>\n";
print "<p>$next_full</p>\n";

if (file_exists($prev_full))
	{
	print "<a href=\"$base/$prev_page_file\">previous</a>";
	if (file_exists($next_full))
		{
		print " | ";
		}
	}
if (file_exists($next_full))
	{
	print "<a href=\"$base/$next_page_file\">next</a>";
	}
else {
	print "does not exist";
	}
}
Else{
include('main_1.php');
} 
?>

 

 

and the information that is printed... as you can see it prints all the variables... but the if loop skils to the else statement and prints "does not exist" rather than a prev link or a next link....

 

base_url=[http://www.mysite.com]

 

full_path=[layouts/anime/anime_1.php]

 

base=[layouts/anime]

 

page_file=[anime_1.php]

 

page_num=[1]

 

partial_path=[anime]

 

prev_page_file=[anime_0.php]

 

next_page_file=[anime_2.php]

 

prev_full=[/layouts/anime/anime_0.php]

 

next_full=[/layouts/anime/anime_2.php]

 

does not exist

Link to comment
https://forums.phpfreaks.com/topic/42476-file_exists-error/
Share on other sites

from what i can see thats a pretty long way of doing what your doing...

 

any files you want to get just put them in a sperate folder from your www folder linke pages/ or something, so no one can edit your header to include their page...

 

now what you want to do is your filexists function and include the page

$page=$_GET['page'];
if (file_exists($filename)) {
include("pages/$page.php");}

 

now its a simple matter of adding the next page and minusing the last page

$next_page=$page+1;
$last_page=$page-1;

i dont thin your that stupid not to know how to do that..

 

now you can do your echos... (place them where you want...)

 

echo "<p>base_url=http:// ."$_SERVER['HTTP_HOST']".</p>\n";

Link to comment
https://forums.phpfreaks.com/topic/42476-file_exists-error/#findComment-206064
Share on other sites

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.