- function put_contents($file, $contents, $mode = false ) {
- if ( ! ($fp = @fopen($file, 'w')) )
+ public function put_contents( $file, $contents, $mode = false ) {
+ $fp = @fopen( $file, 'wb' );
+ if ( ! $fp )
+ return false;
+
+ mbstring_binary_safe_encoding();
+
+ $data_length = strlen( $contents );
+
+ $bytes_written = fwrite( $fp, $contents );
+
+ reset_mbstring_encoding();
+
+ fclose( $fp );
+
+ if ( $data_length !== $bytes_written )