file_exists()期望参数1为有效路径,给定字符串 [英] file_exists() expects parameter 1 to be a valid path, string given

查看:68
本文介绍了file_exists()期望参数1为有效路径,给定字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个Web应用程序,可以根据最终用户来自哪个零售位置对其进行自定义.例如,如果用户来自一家名为农夫市场"的商店,则可能有该用户特定于该特定商店的自定义内容或额外链接. file_exists()用于确定是否需要导入页面的任何自定义部分.

I'm designing a web application that can be customized based on which retail location the end user is coming from. For example, if a user is coming from a store called Farmer's Market, there may be customized content or extra links available to that user, specific to that particular store. file_exists() is used to determine if there are any customized portions of the page that need to be imported.

到目前为止,我们一直在使用一种相对不安全的方法,在该方法中,商品ID#和商店只是作为GET参数传入,并且系统知道将其应用于页面中的每个链接.但是,我们将切换到一种可逆的哈希方法,在该方法中,商店和商品编号被加密(看起来像"gd651hd8h41dg0h81"),而页面仅对它们进行解码并分配商店和ID变量.

Up until now, we've been using a relatively insecure method, in which the item ID# and the store are simply passed in as GET parameters, and the system knows to apply them to each of the links within the page. However, we're switching to a reversible hash method, in which the store and item number are encrypted (to look something like "gd651hd8h41dg0h81"), and the pages simply decode them and assign the store and ID variables.

但是,自那时以来,我们一直遇到一个错误,而Google广泛没有为我找到答案.有几个类似的代码块,但它们看起来都像这样:

Since then, however, we've been running into an error that Googling extensively hasn't found me an answer for. 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);
}

(/stores/目录实际上位于工作目录上方的目录中,因此是../)

(The /stores/ directory is actually in the directory above the working one, hence the ../)

相当简单.但是,尽管在传递常规ID和存储时工作正常,但使用加密的ID会对每个类似的语句抛出此错误:

Fairly straightforward. But despite working fine when a regular ID and store is passed in, using the encrypted ID throws this error for each one of those similar statements:

警告:file_exists()期望参数1为有效路径,在第11行的[删除的网址]中给出的字符串

Warning: file_exists() expects parameter 1 to be a valid path, string given in [url removed] on line 11

我已经将该脚本吐回了完整的URL,并且它似乎正在正确分配$ store.我正在1& 1托管服务器上运行PHP 5.4.11(因为我知道它们在服务器工作方式上存在一些异常),如果有帮助的话.

I've had the script spit back the full URL, and it appears to be assigning $store correctly. I'm running PHP 5.4.11 on 1&1 hosting (because I know they have some abnormalities in the way their servers work), if that helps any.

推荐答案

我之前遇到过相同的错误,但是我不知道我的解决方案是否可以解决您的问题,您需要删除"\ 0"并尝试替换它:

I got the same error before but I don't know if this solution of mine works on your problem you need to remove the "\0" try replace it:

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

对我的案子起作用了.

这篇关于file_exists()期望参数1为有效路径,给定字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆