简体   繁体   English

php无法打开流 - 没有这样的文件或目录

[英]php failed to open stream - no such file or directory

I have the following php code: 我有以下PHP代码:

<html><body>

    <?php include('scores.php?filename=scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML'); ?>
</body>
</html>

You can see the result here: http://apps.facebook.com/krajecr/pokus2.php 你可以在这里看到结果: http//apps.facebook.com/krajecr/pokus2.php

As you can see, it tells me, that it doesn't exist. 如你所见,它告诉我,它不存在。 But if I use just the link: http://apps.facebook.com/krajecr/scores.php?filename=scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML it works fine an I see exactly what I want to see. 但是,如果我只使用链接: http//apps.facebook.com/krajecr/scores.php?filename = scores / score.sco&scoresize = 10&action = view&viewtype = HTML,它工作得很好,我完全看到了我想看到的内容。 Where is the problem please? 请问哪里有问题?

As the error says, "scores.php?filename=scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML" is not a file or directory. 如错误所示,“scores.php?filename = scores / score.sco&scoresize = 10&action = VIEW&viewtype = HTML”不是文件或目录。 Just because you can enter querystring parameters ("?" and after) into your web browser does not mean that these are part of the filename. 仅仅因为您可以在Web浏览器中输入查询字符串参数(“?”和之后)并不意味着它们是文件名的一部分。 The filename is scores.php . 文件名是scores.php

It looks like you want to go and make a request through a webserver rather than just opening a local file. 看起来你想通过网络服务器发出请求,而不仅仅是打开一个本地文件。 Fortunately, include allows that natively too. 幸运的是, include 允许原生 However, you have to specify it: 但是,您必须指定它:

<html>
  <body>
    <?php include('http://someserver.com/scores.php?filename=scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML'); ?>
  </body>
</html>

Alternatively (and preferably, to save an HTTP request), if scores.php is on the same webserver, you can access it as a normal file but set the $_GET parameters beforehand, as these will survive through the include directive: 或者(最好是保存HTTP请求),如果scores.php在同一个Web服务器上,您可以将其作为普通文件访问,但事先设置$_GET参数,因为这些参数将通过include指令生存:

<html>
  <body>
    <?php
    $_GET = Array('filename' => 'scores/score.sco'); // add the others here too
    include('scores.php');
    ?>
  </body>
</html>

Hope that helps. 希望有所帮助。

The problem is that you've specified it as an access via the filesystem, when you actually need to have it access via the web server. 问题是,当您确实需要通过Web服务器访问它时,您已将其指定为通过文件系统进行访问。 Put in the full URL. 输入完整的URL。

Better yet, convert the script to include into a function and then include and call it. 更好的是,将脚本转换为包含到函数中,然后包含并调用它。

As far as I know, you cannot use an include with parameters, it must be a file name. 据我所知,你不能使用带参数的include,它必须是文件名。 You can set the $_GET['var'] = 'value'; 你可以设置$ _GET ['var'] ='value'; before your call to include for a way that does work. 在你打电话之前包括一个有效的方式。

you cannot do an include with get values. 你不能用get值来包含。

you can set all ur ness get values with 您可以设置所有urss获取值

$_GET[..] = ... $ _GET [..] = ...

and then do 然后呢

include('scores.php') 包括( 'scores.php')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM