WP_Filesystem_FTPext::put_contents( string $file, string $contents, bool|int $mode = false )


Parameters

$file

(Required)

$contents

(Required)

$mode

(Optional)

Default value: false


Return

(bool)


Source

File: wp-admin/includes/class-wp-filesystem-ftpext.php

	public function put_contents($file, $contents, $mode = false ) {
		$tempfile = wp_tempnam($file);
		$temp = fopen( $tempfile, 'wb+' );

		if ( ! $temp ) {
			unlink( $tempfile );
			return false;
		}

		mbstring_binary_safe_encoding();

		$data_length = strlen( $contents );
		$bytes_written = fwrite( $temp, $contents );

		reset_mbstring_encoding();

		if ( $data_length !== $bytes_written ) {
			fclose( $temp );
			unlink( $tempfile );
			return false;
		}

		fseek( $temp, 0 ); // Skip back to the start of the file being written to

		$ret = @ftp_fput( $this->link, $file, $temp, FTP_BINARY );

		fclose($temp);
		unlink($tempfile);

		$this->chmod($file, $mode);

		return $ret;
	}