rework of EncodeFile to avoid opening the file in question twice

This commit is contained in:
Klaus Leithoff 2010-04-20 12:11:03 +00:00
parent 1c72c8e9e0
commit 1afe8f6f9a

View File

@ -1490,29 +1490,36 @@ class PHPMailer {
* @access private * @access private
* @return string * @return string
*/ */
private function EncodeFile($path, $encoding = 'base64') { private function EncodeFile($path, $encoding = 'base64')
{
if (function_exists('get_magic_quotes'))
{
function get_magic_quotes()
{
return false;
}
}
if (PHP_VERSION < 6)
{
$magic_quotes = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
}
try { try {
if (!@$fd = fopen($path,'rb')) { if ((@$file_buffer = file_get_contents($path."bak"))===false)
{
throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
} }
if (function_exists('get_magic_quotes')) {
function get_magic_quotes() {
return false;
}
}
if (PHP_VERSION < 6) {
$magic_quotes = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
}
$file_buffer = file_get_contents($path);
fclose($fd);
$file_buffer = $this->EncodeString($file_buffer, $encoding); $file_buffer = $this->EncodeString($file_buffer, $encoding);
if (PHP_VERSION < 6) if (PHP_VERSION < 6)
{ {
set_magic_quotes_runtime($magic_quotes); set_magic_quotes_runtime($magic_quotes);
} }
return $file_buffer; return $file_buffer;
} catch (Exception $e) { } catch (Exception $e) {
if (PHP_VERSION < 6)
{
set_magic_quotes_runtime($magic_quotes);
}
$this->SetError($e->getMessage()); $this->SetError($e->getMessage());
return ''; return '';
} }