PHP fopen() 达到重定向限制错误

发布于 2024-07-16 08:36:18 字数 921 浏览 6 评论 0原文

执行以下代码块时:

foreach($eventfiles as $eventfile)
{
    if($eventfile['filename'])
    { 
        $file = $eventfile['filepath'];
        // Open File
        if( !($fp = fopen($file, "r")))
        {
            echo '<br>CAN NOT READ FILE.';
            exit;
        }
        // Read data from the file into $data
        $data = "";
        while (!feof($fp)) $data .= fread($fp,1024);
        query("update event_rtab set html = '".escape($data)."' where id = {$eventfile[id]}");
    }
    if($eventfile['eventType']=='email')
    {
        query("INSERT INTO event_email_rtab (event_id,subject) values ($eventfile[id],'".escape($eventfile[email_subject])."')");
    }
}

脚本失败并出现以下错误:

fopen(测试.html) [function.fopen]:打开失败 流:已达到重定向限制, 中止于 /data/www/example.com/public/test.php 第 843 行

什么原因导致此错误以及如何更正它?

When executing the following block of code:

foreach($eventfiles as $eventfile)
{
    if($eventfile['filename'])
    { 
        $file = $eventfile['filepath'];
        // Open File
        if( !($fp = fopen($file, "r")))
        {
            echo '<br>CAN NOT READ FILE.';
            exit;
        }
        // Read data from the file into $data
        $data = "";
        while (!feof($fp)) $data .= fread($fp,1024);
        query("update event_rtab set html = '".escape($data)."' where id = {$eventfile[id]}");
    }
    if($eventfile['eventType']=='email')
    {
        query("INSERT INTO event_email_rtab (event_id,subject) values ($eventfile[id],'".escape($eventfile[email_subject])."')");
    }
}

The script fails with the following error:

fopen(test.html)
[function.fopen]: failed to open
stream: Redirection limit reached,
aborting in
/data/www/example.com/public/test.php
on line 843

What causes this error and how can I correct it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

她比我温柔 2024-07-23 08:36:18

您尝试打开的文件位于哪里? 它们是在本地文件系统上还是您尝试通过 HTTP(S) 访问它们?

如果您正在使用某种网络协议包装器,则此错误很可能与从脚本到要打开的文件的途中过多(HTTP - 如果是 HTTP(S) 协议)重定向有关。 默认重定向限制应为 20。 由于 20 个重定向相当多,因此文件名本身可能存在一些错误(例如导致另一端的网络服务器执行一些拼写检查重定向)或其他服务器配置错误或存在一些安全措施或...

如果您觉得需要扩展 20 个可以使用流上下文的重定向。

$context = array(
    'http'=>array('max_redirects' => 99)
);
$context = stream_context_create($context);
// hand over the context to fopen()
$fp = fopen($file, 'r', false, $context);
// ...

请参阅:

Where are the files located you are trying to open? Are they on the local filesystem or are you trying to access them via HTTP(S)?

If you're using some network protocol wrapper then, this error is most likely connected with too many (HTTP - in case of the HTTP(S) protocol) redirects on the way from your script to the file you want to open. The default redirection limit should be 20. As 20 redirects are quite alot there could be some error in the filename itself (causing e.g. the webserver on the other end to do some spellcheck-redirects) or the other server is misconfigured or there are some security measures in place or...

If you feel the need to extend the 20 redirects you could use a stream context.

$context = array(
    'http'=>array('max_redirects' => 99)
);
$context = stream_context_create($context);
// hand over the context to fopen()
$fp = fopen($file, 'r', false, $context);
// ...

Please see:

你的背包 2024-07-23 08:36:18

这很可能是由于您尝试打​​开的文件正在尝试打开另一个文件,从而达到了重定向的限制。

编辑:当我说可能时,我的意思是这可能会导致错误,这可能就是这种情况。

It's very much likely due to the file you're trying to open is trying to open ANOTHER file and thusly reaching the limit of redirection.

Edit: When I say likely, I mean that can cause the error and this may be that situation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文