Skip to content
Permalink
Browse files

Make readBase64 an instance method

Leverage the existing code in File::read() and simply add in chunking and base64 encoding.
  • Loading branch information...
jmillerdesign committed May 17, 2013
1 parent dfdde95 commit 4a4ca7c8d40fb94b50740a6998f9238b7f7b4f5b
Showing with 5 additions and 9 deletions.
  1. +2 −1 lib/Cake/Network/Email/CakeEmail.php
  2. +3 −8 lib/Cake/Utility/File.php
@@ -1385,7 +1385,8 @@ protected function _attachFiles($boundary = null) {
* @return string File contents in base64 encoding
*/
protected function _readFile($file) {
return File::readAndBase64Encode($file);
$f = new File($file);
return $f->readBase64();
}
/**
@@ -181,18 +181,13 @@ public function read($bytes = false, $mode = 'rb', $force = false) {
}
/**
* Read the file contents and return a base64 version of the file contents.
* Return the contents of this File as 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;
public function readBase64() {
return chunk_split(base64_encode($this->read()));
}
/**

0 comments on commit 4a4ca7c

Please sign in to comment.
You can’t perform that action at this time.