CMS MADE SIMPLE FORGE

CMS Made Simple Core

 

[#3794] Remove use of readfile.

avatar
Created By: Bob Sideshow (sideshowbob)
Date Submitted: Tue Jul 28 13:50:24 -0400 2009

Assigned To: Ted Kulp (wishy)
Version: 1.8.2
CMSMS Version: None
Severity: Minor
Resolution: Fixed
State: Closed
Summary:
Remove use of readfile.
Detailed Description:
Please replace all instances of readfile with echo file_get_contents.

Readfile is disabled by some hosts and the workaround in misc.functions.php
doesn't work. You receive an error saying "cannot redeclare function" or
something similar.

This issue crops up a number of times in a number or ways in the forum and often
confuses the less experienced.


History

Comments
avatar
Date: 2009-09-18 06:20
Posted By: luca clemenzi (clemmy)

i can confirm this: of the host disables readfile, the workaround present in
misc.functions.php makes all the site unavailable (fatal error: cannot redeclare
function).

to make it work I changed the name of the function (third line) in this way

if(!function_exists("readfile"))
{
    function readfile2($filename)
    {
      @ob_start();
      echo file_get_contents($filename);
      $result = @ob_get_contents();
      @ob_end_clean();
      if( !empty($result) ) {
	echo $result;
        return TRUE;
      }
      return FALSE;
    }
}

and then I had to change all occurence of readfile with readfile2 in all files
in my installation
      
avatar
Date: 2009-11-28 13:23
Posted By: Jasper E (JasperE)

I also got the cannot redeclare reafile error on my host.
Luca Clemenzi's readfile2 function solved my problem.
(Thanks!)
      
avatar
Date: 2010-04-09 18:09
Posted By: Robert Campbell (calguy1000)

Fixed for 1.7.1
      
avatar
Date: 2010-05-07 12:33
Posted By: Ronny Krijt (ronnyk)

1.7.1 is released.
      
avatar
Date: 2010-08-03 20:48
Posted By: fabien guillard (boby)

I have the same problem with 1.8.1

Cannot redeclare readfile() in /
/lib/misc.functions.php on line 1396

Thanks
      
avatar
Date: 2010-10-14 04:50
Posted By: Bob Sideshow (sideshowbob)

Sorry to re-open this one but readfile is still being used (as of 1.8.2). Also
the 'workaround' in misc.functions.php still exists which causes cmsms to be
unusable on affected hosts.

Readfile use occurs:
/admin/style.php - Lines 28 & 32
/lib/misc.functions.php Line 1393. This entire function needs to be removed.
      
avatar
Date: 2011-01-07 13:58
Posted By: Ronny Krijt (ronnyk)

Addressed for 1.9.3
      
avatar
Date: 2011-01-16 15:28
Posted By: Robert Campbell (calguy1000)

Fixed in R6956
      
avatar
Date: 2011-02-09 09:27
Posted By: Rolf (rolf1)

1.9.3 is released
      
Updates

Updated: 2011-02-09 09:27
state: Open => Closed

Updated: 2011-01-16 15:28
resolution_id: 6 => 7

Updated: 2011-01-07 13:58
resolution_id: 5 => 6
assigned_to_id: 4160 => 102

Updated: 2010-10-14 04:50
version_id: 28005 => 28620
resolution_id: 7 => 5
assigned_to_id: 100 => 4160
state: Closed => Open

Updated: 2010-05-07 12:33
state: Open => Closed

Updated: 2010-04-09 18:09
resolution_id: => 7