mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
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:
@@ -75,20 +75,16 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->ftp->SetType(FTP_AUTOASCII);
|
||||
$this->ftp->Passive(true);
|
||||
$this->ftp->setTimeout(FS_TIMEOUT);
|
||||
$this->ftp->SetType( FTP_BINARY );
|
||||
$this->ftp->Passive( true );
|
||||
$this->ftp->setTimeout( FS_TIMEOUT );
|
||||
return true;
|
||||
}
|
||||
|
||||
function get_contents($file, $type = '', $resumepos = 0) {
|
||||
function get_contents( $file ) {
|
||||
if ( ! $this->exists($file) )
|
||||
return false;
|
||||
|
||||
if ( empty($type) )
|
||||
$type = FTP_AUTOASCII;
|
||||
$this->ftp->SetType($type);
|
||||
|
||||
$temp = wp_tempnam( $file );
|
||||
|
||||
if ( ! $temphandle = fopen($temp, 'w+') )
|
||||
@@ -122,11 +118,14 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
|
||||
return false;
|
||||
}
|
||||
|
||||
fwrite($temphandle, $contents);
|
||||
fseek($temphandle, 0); //Skip back to the start of the file being written to
|
||||
$bytes_written = fwrite( $temphandle, $contents );
|
||||
if ( false === $bytes_written || $bytes_written != strlen( $contents ) ) {
|
||||
fclose( $temphandle );
|
||||
unlink( $temp );
|
||||
return false;
|
||||
}
|
||||
|
||||
$type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
|
||||
$this->ftp->SetType($type);
|
||||
fseek( $temphandle, 0 ); // Skip back to the start of the file being written to
|
||||
|
||||
$ret = $this->ftp->fput($file, $temphandle);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user