Make readBase64 an instance method

Leverage the existing code in File::read() and simply add in chunking and base64 encoding.
This commit is contained in:
J Miller 2013-05-16 18:56:46 -07:00
parent dfdde954ea
commit 4a4ca7c8d4
2 changed files with 5 additions and 9 deletions

View file

@ -1385,7 +1385,8 @@ class CakeEmail {
* @return string File contents in base64 encoding
*/
protected function _readFile($file) {
return File::readAndBase64Encode($file);
$f = new File($file);
return $f->readBase64();
}
/**

View file

@ -181,18 +181,13 @@ class File {
}
/**
* 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()));
}
/**