Make WordPress Core


Ignore:
Timestamp:
09/26/2008 06:53:57 AM (17 years ago)
Author:
westi
Message:

Autodetect binary files for FTP filesystems. Fixes #7568 props DD32.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-filesystem-ftpext.php

    r8811 r8990  
    2323    var $permission = null;
    2424
    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_BINARY
    38                             );
    39 
    4025    function WP_Filesystem_FTPext($opt='') {
    4126        $this->method = 'ftpext';
     
    10489
    10590    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
    11094        $temp = tmpfile();
    11195        if ( ! $temp )
    11296            return false;
     97
    11398        if( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) )
    11499            return false;
     100
    115101        fseek($temp, 0); //Skip back to the start of the file being written to
    116102        $contents = '';
    117         while (!feof($temp)) {
     103
     104        while ( ! feof($temp) )
    118105            $contents .= fread($temp, 8192);
    119         }
     106
    120107        fclose($temp);
    121108        return $contents;
     
    125112    }
    126113    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
    131117        $temp = tmpfile();
    132118        if ( ! $temp )
    133119            return false;
     120
    134121        fwrite($temp, $contents);
    135122        fseek($temp, 0); //Skip back to the start of the file being written to
     123
    136124        $ret = @ftp_fput($this->link, $file, $temp, $type);
     125
    137126        fclose($temp);
    138127        return $ret;
Note: See TracChangeset for help on using the changeset viewer.