mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Create method readAndBase64Encode() in File utility.
Move this utility method out of CakeEmail, which allows other Mail transports to encode files manually. Maintains BC.
This commit is contained in:
parent
f47609bd61
commit
dfdde954ea
2 changed files with 20 additions and 8 deletions
|
@ -21,6 +21,7 @@
|
|||
App::uses('Validation', 'Utility');
|
||||
App::uses('Multibyte', 'I18n');
|
||||
App::uses('AbstractTransport', 'Network/Email');
|
||||
App::uses('File', 'Utility');
|
||||
App::uses('String', 'Utility');
|
||||
App::uses('View', 'View');
|
||||
App::import('I18n', 'Multibyte');
|
||||
|
@ -1359,7 +1360,7 @@ class CakeEmail {
|
|||
if (!empty($fileInfo['contentId'])) {
|
||||
continue;
|
||||
}
|
||||
$data = $this->readFile($fileInfo['file']);
|
||||
$data = $this->_readFile($fileInfo['file']);
|
||||
|
||||
$msg[] = '--' . $boundary;
|
||||
$msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
|
||||
|
@ -1383,12 +1384,8 @@ class CakeEmail {
|
|||
* @param string $file The file to read.
|
||||
* @return string File contents in base64 encoding
|
||||
*/
|
||||
public function readFile($file) {
|
||||
$handle = fopen($file, 'rb');
|
||||
$data = fread($handle, filesize($file));
|
||||
$data = chunk_split(base64_encode($data));
|
||||
fclose($handle);
|
||||
return $data;
|
||||
protected function _readFile($file) {
|
||||
return File::readAndBase64Encode($file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1407,7 +1404,7 @@ class CakeEmail {
|
|||
if (empty($fileInfo['contentId'])) {
|
||||
continue;
|
||||
}
|
||||
$data = $this->readFile($fileInfo['file']);
|
||||
$data = $this->_readFile($fileInfo['file']);
|
||||
|
||||
$msg[] = '--' . $boundary;
|
||||
$msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
|
||||
|
|
|
@ -180,6 +180,21 @@ class File {
|
|||
return trim($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the file contents and return a base64 version of the file contents.
|
||||
*
|
||||
* @param string $file The file to read.
|
||||
* @return string File contents in base64 encoding
|
||||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::readAndBase64Encode
|
||||
*/
|
||||
public static function readAndBase64Encode($file) {
|
||||
$handle = fopen($file, 'rb');
|
||||
$data = fread($handle, filesize($file));
|
||||
$data = chunk_split(base64_encode($data));
|
||||
fclose($handle);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets or gets the offset for the currently opened file.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue