From 51d601058cae35eff9317577a37b0a2e31a547c3 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Thu, 20 Nov 2008 22:43:07 +0000 Subject: [PATCH] Convert getFile function to simpler PHP5 version Add a unit test for getFile --- class.phpmailer.php | 12 ++---------- test/phpmailer_test.php | 6 ++++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/class.phpmailer.php b/class.phpmailer.php index cc9925e1..569d303a 100644 --- a/class.phpmailer.php +++ b/class.phpmailer.php @@ -1935,18 +1935,10 @@ class PHPMailer { * * @access public * @param string $filename Parameter File Name + * @return string (or boolean false if it fails to read for any reason) */ public function getFile($filename) { - $return = ''; - if ($fp = fopen($filename, 'rb')) { - while (!feof($fp)) { - $return .= fread($fp, 1024); - } - fclose($fp); - return $return; - } else { - return false; - } + return @file_get_contents($filename); } /** diff --git a/test/phpmailer_test.php b/test/phpmailer_test.php index 45bc1f75..15221eaf 100644 --- a/test/phpmailer_test.php +++ b/test/phpmailer_test.php @@ -565,6 +565,12 @@ class phpmailerTest extends TestCase $this->assert(false, 'No language files found!'); } } + + //Check that getFile works + function test_getFile() { + $a = $this->Mail->getFile('../class.phpmailer.php'); //Point at any non-empty file + $this->assert(($a !== false), 'GetFile failed to read a file.'); + } } /** * Create and run test instance.