包含 - 与直接链接不同的结果
我有以下 php 代码:
<html>
<body>
<?php
$_GET = Array('filename' => 'scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML'); // add the others here too
include('scores.php');
?>
</body>
</html>
使用此代码,我尝试包含此 http://apps.facebook.com/krajecr/scores.php?filename=scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML< /a> 直接链接有效,但您可以在此处看到包含的结果: http://apps.facebook .com/krajecr/pokus.php - 错误:警告:fclose():提供的参数不是 /3w/webz.cz/p/programming/facebook/scores.php 中的有效流资源第 9 行
你能帮我解决这个问题吗?
Scores.php 可以在这里找到 http://www.scores.php flashkit.com/tutorials/Games/High-sco-Glen_Rho-657/index.php ()
这里是前 10 行:
<?php
$winscore = (int)$winscore;
// Create a Blank File if it doesn't already exist
if (!file_exists($filename))
{
$file=fopen($filename, "w");
fclose ($file);
}
I have the following php code:
<html>
<body>
<?php
$_GET = Array('filename' => 'scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML'); // add the others here too
include('scores.php');
?>
</body>
</html>
With this code I'm trying to include this http://apps.facebook.com/krajecr/scores.php?filename=scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML
The direct link works, but you can see the result from the inclusion here: http://apps.facebook.com/krajecr/pokus.php - error: Warning: fclose(): supplied argument is not a valid stream resource in /3w/webz.cz/p/programming/facebook/scores.php on line 9
Can you please help me solve this?
scores.php can be found here http://www.flashkit.com/tutorials/Games/High-sco-Glen_Rho-657/index.php ()
here are the first 10 lines:
<?php
$winscore = (int)$winscore;
// Create a Blank File if it doesn't already exist
if (!file_exists($filename))
{
$file=fopen($filename, "w");
fclose ($file);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误表明您正在尝试对非流资源的内容执行
fclose
操作。假设您从
fopen
获取了$file
,这里唯一的情况是fopen
失败,因此$file
不是流资源,而是FALSE
。例如,如果您的网络服务器运行的用户没有创建该文件的权限,则可能会失败。为您的函数调用添加错误检查。
我无法解释为什么当您让 PHP 通过网络执行包含请求时情况会有所不同。
编辑
应该是
绝对在任何地方退出尝试使用HTTP查询字符串语法;世界不是这样运作的!
我还注意到“scores.php”似乎从未定义
$filename
是什么。难怪文件创建失败:您从未给它提供有效的文件名来创建!检查fopen
的返回值(正如您始终应该做的那样)会发现此错误。您可能想写
$_GET['filename']
。The error says that you're trying to do
fclose
on something that's not a stream resource.Assuming you got
$file
fromfopen
, the only scenario here is that thefopen
failed so that$file
is not a stream resource, butFALSE
. It might fail if, for example, the user that your webserver is running as does not have permissions to create the file.Add error checking to your function calls.
I can't explain why this would be different when you have PHP do the inclusion request over the web.
Edit
should be
Quit trying to use HTTP querystring syntax absolutely everywhere; that's not how the world works!
I also notice that "scores.php" never seems to define what
$filename
is. No wonder the file creation is failing: you never give it a valid filename to create! Checking the return value offopen
— as you always should — would have revealed this error.You probably meant to write
$_GET['filename']
.