Standardise WP_Filesystem_*::put_contents() arguments to support chmod reliably across all transports. Fixes #10889

git-svn-id: https://develop.svn.wordpress.org/trunk@12723 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse
2010-01-14 09:23:53 +00:00
parent c1f8977b95
commit 76592af8d8
5 changed files with 24 additions and 19 deletions
@@ -115,14 +115,9 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
return explode("\n", $this->get_contents($file) );
}
function put_contents($file, $contents, $type = '' ) {
if ( empty($type) )
$type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
$this->ftp->SetType($type);
function put_contents($file, $contents, $mode = false ) {
$temp = wp_tempnam( $file );
if ( ! $temphandle = fopen($temp, 'w+') ) {
if ( ! $temphandle = @fopen($temp, 'w+') ) {
unlink($temp);
return false;
}
@@ -130,10 +125,16 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
fwrite($temphandle, $contents);
fseek($temphandle, 0); //Skip back to the start of the file being written to
$type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
$this->ftp->SetType($type);
$ret = $this->ftp->fput($file, $temphandle);
fclose($temphandle);
unlink($temp);
$this->chmod($file, $mode);
return $ret;
}