Skip to content

Commit

Permalink
Make readBase64 an instance method
Browse files Browse the repository at this point in the history
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 4a4ca7c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/Cake/Network/Email/CakeEmail.php
Expand Up @@ -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();
}

/**
Expand Down
11 changes: 3 additions & 8 deletions lib/Cake/Utility/File.php
Expand Up @@ -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()));
}

/**
Expand Down

0 comments on commit 4a4ca7c

Please sign in to comment.