Changeset 8990
- Timestamp:
- 09/26/2008 06:53:57 AM (17 years ago)
- Location:
- trunk/wp-admin/includes
- Files:
-
- 3 edited
-
class-wp-filesystem-base.php (modified) (1 diff)
-
class-wp-filesystem-ftpext.php (modified) (3 diffs)
-
class-wp-filesystem-ftpsockets.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-wp-filesystem-base.php
r8645 r8990 167 167 return $newmode; 168 168 } 169 170 /** 171 * Determines if the string provided contains binary characters. 172 * 173 * @since 2.7 174 * @package WordPress 175 * @subpackage WP_Filesystem 176 * 177 * @param string $text String to test against 178 * 179 */ 180 function is_binary( $text ) { 181 return (bool) preg_match('|[^\x20-\x7E]|', $text); //chr(32)..chr(127) 182 } 169 183 } 170 184 -
trunk/wp-admin/includes/class-wp-filesystem-ftpext.php
r8811 r8990 23 23 var $permission = null; 24 24 25 var $filetypes = array(26 'php'=>FTP_ASCII,27 'css'=>FTP_ASCII,28 'txt'=>FTP_ASCII,29 'js'=>FTP_ASCII,30 'html'=>FTP_ASCII,31 'htm'=>FTP_ASCII,32 'xml'=>FTP_ASCII,33 34 'jpg'=>FTP_BINARY,35 'png'=>FTP_BINARY,36 'gif'=>FTP_BINARY,37 'bmp'=>FTP_BINARY38 );39 40 25 function WP_Filesystem_FTPext($opt='') { 41 26 $this->method = 'ftpext'; … … 104 89 105 90 function get_contents($file, $type = '', $resumepos = 0 ){ 106 if( empty($type) ){ 107 $extension = substr(strrchr($file, "."), 1); 108 $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII; 109 } 91 if( empty($type) ) 92 $type = FTP_BINARY; 93 110 94 $temp = tmpfile(); 111 95 if ( ! $temp ) 112 96 return false; 97 113 98 if( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) ) 114 99 return false; 100 115 101 fseek($temp, 0); //Skip back to the start of the file being written to 116 102 $contents = ''; 117 while (!feof($temp)) { 103 104 while ( ! feof($temp) ) 118 105 $contents .= fread($temp, 8192); 119 } 106 120 107 fclose($temp); 121 108 return $contents; … … 125 112 } 126 113 function put_contents($file, $contents, $type = '' ) { 127 if( empty($type) ) { 128 $extension = substr(strrchr($file, "."), 1); 129 $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII; 130 } 114 if( empty($type) ) 115 $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; 116 131 117 $temp = tmpfile(); 132 118 if ( ! $temp ) 133 119 return false; 120 134 121 fwrite($temp, $contents); 135 122 fseek($temp, 0); //Skip back to the start of the file being written to 123 136 124 $ret = @ftp_fput($this->link, $file, $temp, $type); 125 137 126 fclose($temp); 138 127 return $ret; -
trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php
r8645 r8990 23 23 var $permission = null; 24 24 25 var $filetypes = array(26 'php' => FTP_ASCII,27 'css' => FTP_ASCII,28 'txt' => FTP_ASCII,29 'js' => FTP_ASCII,30 'html'=> FTP_ASCII,31 'htm' => FTP_ASCII,32 'xml' => FTP_ASCII,33 34 'jpg' => FTP_BINARY,35 'png' => FTP_BINARY,36 'gif' => FTP_BINARY,37 'bmp' => FTP_BINARY38 );39 40 25 function WP_Filesystem_ftpsockets($opt = '') { 41 26 $this->method = 'ftpsockets'; … … 106 91 return false; 107 92 108 if( empty($type) ){ 109 $extension = substr(strrchr($file, '.'), 1); 110 $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_AUTOASCII; 111 } 93 if( empty($type) ) 94 $type = FTP_AUTOASCII; 112 95 $this->ftp->SetType($type); 96 113 97 $temp = wp_tempnam( $file ); 98 114 99 if ( ! $temphandle = fopen($temp, 'w+') ) 115 100 return false; 101 116 102 if ( ! $this->ftp->fget($temphandle, $file) ) { 117 103 fclose($temphandle); … … 119 105 return ''; //Blank document, File does exist, Its just blank. 120 106 } 107 121 108 fseek($temphandle, 0); //Skip back to the start of the file being written to 122 109 $contents = ''; 110 123 111 while ( ! feof($temphandle) ) 124 112 $contents .= fread($temphandle, 8192); 113 125 114 fclose($temphandle); 126 115 unlink($temp); … … 133 122 134 123 function put_contents($file, $contents, $type = '' ) { 135 if( empty($type) ){ 136 $extension = substr(strrchr($file, '.'), 1); 137 $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_AUTOASCII; 138 } 124 if( empty($type) ) 125 $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; 126 139 127 $this->ftp->SetType($type); 140 128 … … 144 132 return false; 145 133 } 134 146 135 fwrite($temphandle, $contents); 147 136 fseek($temphandle, 0); //Skip back to the start of the file being written to 137 148 138 $ret = $this->ftp->fput($file, $temphandle); 139 149 140 fclose($temphandle); 150 141 unlink($temp);
Note: See TracChangeset
for help on using the changeset viewer.