PHP fopen()重定向限制达到错误 [英] PHP fopen() Redirection Limit Reached Error

查看:85
本文介绍了PHP fopen()重定向限制达到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行以下代码块时:

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]:打开失败 流:已达到重定向限制, 流产 /data/www/example.com/public/test.php 在843行上

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?

推荐答案

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

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)?

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

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...

如果您需要扩展20个重定向,则可以使用流上下文.

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);
// ...

请参阅:

  • Streams
  • stream_context_create()
  • HTTP context options

这篇关于PHP fopen()重定向限制达到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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