- function put_contents($file, $contents, $mode = false, $type = '') {
- if ( ! ($fp = @fopen($file, 'w' . $type)) )
+
+ /**
+ * Write a string to a file
+ *
+ * @access public
+ *
+ * @param string $file Remote path to the file where to write the data.
+ * @param string $contents The data to write.
+ * @param int $mode Optional. The file permissions as octal number, usually 0644.
+ * Default false.
+ * @return bool False upon failure, true otherwise.
+ */
+ 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 )