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?
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.
Please see:
stream_context_create()