File_exists () expects parameter 1 to be a valid path, string given

I am developing a web application that can be customized based on which retail location the end user comes from. For example, if a user comes from a store called Farmer Market, they can be configured with content or sitelinks specific to that particular store. file_exists () is used to determine if there are any custom parts of the page that need to be imported.

So far, we have used a relatively unsafe method, in which the element identifier and storage are simply passed as GET parameters, and the system knows how to apply them to each of the links on the page. Nevertheless, we move on to a reversible hash method, in which the store number and numbers are stored (to look something like this: "gd651hd8h41dg0h81"), and the pages simply decode them and assign storage and identifier variables.

Since then, however, we have encountered a mistake that Google did not find an answer for me. There are several similar blocks of code, but they all look something like this:

$buttons_first = "../stores/" . $store . "/buttons_first.php"; if(file_exists($buttons_first)) { include($buttons_first); } 

(the / stores / directory is located above the working directory, therefore ... /)

Pretty simple. But, despite the fact that it works fine when using a regular identifier and storage, using an encrypted identifier causes this error for each of these similar operators:

Warning: file_exists () expects parameter 1 to be a valid path, the line specified in [url deleted] on line 11

I had a typesetting script of the full url and it seems to be assigning $ store correctly. I am running PHP 5.4.11 on 1 and 1 hosting (because I know that they have some deviations in the operation of their servers), if that helps anyone.

+6
source share
4 answers

I have the same error, but I don’t know if this solution of my work should solve your problem, I need to delete "\ 0", try replacing it:

 $cleaned = strval(str_replace("\0", "", $buttons_first)); 

he worked on my case.

+11
source

Run var_dump (strpos ($ buttons_first, "\ 0")), this warning may occur when the path has a zero byte for security reasons. If this does not work, check the line length and make sure that this is what you expect, just in case there are other invisible bytes.

+2
source

This may be a contour issue, as it depends on where you are running the script. It is safer to use absolute paths. To get the path to the directory where the current script is running, you can use dirname(__FILE__) .

+1
source

Add / in front of shops /, you better use absolute paths ...

0
source

All Articles