WP_Filesystem: Ensure that all files are read/written correctly by verifying the return values from fwrite() and using FTP_BINARY mode (ASCII converts line endings as per the spec). See #25237

git-svn-id: https://develop.svn.wordpress.org/trunk@25304 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse
2013-09-09 02:42:52 +00:00
parent d92f3ab536
commit 2f40784d97
4 changed files with 42 additions and 30 deletions
@@ -59,12 +59,20 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
* @param int $mode (optional) The file permissions as octal number, usually 0644.
* @return bool False upon failure.
*/
function put_contents($file, $contents, $mode = false ) {
if ( ! ($fp = @fopen($file, 'w')) )
function put_contents( $file, $contents, $mode = false ) {
$fp = @fopen( $file, 'wb' );
if ( ! $fp )
return false;
@fwrite($fp, $contents);
@fclose($fp);
$this->chmod($file, $mode);
$bytes_written = fwrite( $fp, $contents );
fclose( $fp );
if ( false === $bytes_written || $bytes_written != strlen( $contents ) )
return false;
$this->chmod( $file, $mode );
return true;
}
/**