Jump to content

file_exists returning TRUE even though the file patently doesn't exist!


markowe

Recommended Posts

*delurk! It had to happen sooner or later!*

 

OK, I am totally and utterly stumped. I have this script:

 

	$this->clear_cache ($this->cache_dir, $this->cache_time);

if ($this->cache_time > 0) {	
	$current_page = $_SERVER ['REQUEST_URI'];
	$current_page_encoded = base64_encode($current_page);
	$current_page_path = $this->cache_dir . $current_page_encoded;

	 if (file_exists($current_page_path)) { // see if there is still a file with the name of the current request URI after cache cleared
                $content = file_get_contents ($current_page_path);

		return $content;
                } 
         }

 

Basically, it is for checking if there is a cached version of the page before running the rest of the script, using the REQUEST_URI as the identifier. So it calls a function to clear the cache, which works fine (and I've tried just deleting the cache files manually anyway).

 

Then it checks if we are even caching, i.e. if cache time is greater than 0. Then it uses the BASE64-encoded REQUEST_URI (under which name the file would have been cached previously) to check if a file with that name still exists in the cache dir, and if so loads it. Now, this works perfectly with a url like:

 

mysite/myscript/mysubpage

 

But when the page has parameters, like:

 

mysite/myscript/mysubpage?search=widgets

 

the file_exists function returns TRUE, even though the directory is empty. I did do a clearstatcache(); but it made no difference and anyway, it wouldn't explain why the URI with query string would fail while the regular one would not. And even if something is wrong with my code elsewhere, the fact is it is returning TRUE for a non-existent file.

 

Can someone prevent my slide into insanity?!

Link to comment
Share on other sites

That's the weird thing (forgot to mention, I tried that) - when I echo that, I get the correct path, complete with the query string! I also tried decoding the BASE64 using an online tool to be sure, and it displays the correct path with query string and all. I am totally bemused, to the extent that I have turned off caching for pages with url parameters, but that's really not the solution long-term!

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.