コード例 #1
0
ファイル: post.func.php プロジェクト: lilhorse/cocoa
function ftpupload($source, $attach)
{
    global $authkey, $ftp;
    $ftp['pwd'] = isset($ftp['pwd']) ? $ftp['pwd'] : FALSE;
    $dest = $attach['attachment'];
    if ($ftp['on'] && (!$ftp['allowedexts'] && !$ftp['disallowedexts'] || $ftp['allowedexts'] && in_array($attach['ext'], explode("\n", strtolower($ftp['allowedexts']))) || $ftp['disallowedexts'] && !in_array($attach['ext'], explode("\n", strtolower($ftp['disallowedexts'])))) && (!$ftp['minsize'] || $attach['size'] >= $ftp['minsize'] * 1024)) {
        require_once DISCUZ_ROOT . './include/ftp.func.php';
        if (!$ftp['connid']) {
            if (!($ftp['connid'] = dftp_connect($ftp['host'], $ftp['username'], authcode($ftp['password'], 'DECODE', md5($authkey)), $ftp['attachdir'], $ftp['port'], $ftp['ssl']))) {
                if ($ftp['mirror'] == 1) {
                    ftpupload_error($source, $attach);
                } else {
                    return 0;
                }
            }
            $ftp['pwd'] = FALSE;
        }
        $tmp = explode('/', $dest);
        if (count($tmp) > 1) {
            if (!$ftp['pwd'] && !dftp_chdir($ftp['connid'], $tmp[0])) {
                if (!dftp_mkdir($ftp['connid'], $tmp[0])) {
                    errorlog('FTP', "Mkdir '{$ftp['attachdir']}/{$tmp['0']}' error.", 0);
                    if ($ftp['mirror'] == 1) {
                        ftpupload_error($source, $attach);
                    } else {
                        return 0;
                    }
                }
                if (!function_exists('ftp_chmod') || !dftp_chmod($ftp['connid'], 0777, $tmp[0])) {
                    dftp_site($ftp['connid'], "'CHMOD 0777 {$tmp['0']}'");
                }
                if (!dftp_chdir($ftp['connid'], $tmp[0])) {
                    errorlog('FTP', "Chdir '{$ftp['attachdir']}/{$tmp['0']}' error.", 0);
                    if ($ftp['mirror'] == 1) {
                        ftpupload_error($source, $attach);
                    } else {
                        return 0;
                    }
                }
                dftp_put($ftp['connid'], 'index.htm', $GLOBALS['attachdir'] . '/index.htm', FTP_BINARY);
            }
            $dest = $tmp[1];
            $ftp['pwd'] = TRUE;
        }
        if (dftp_put($ftp['connid'], $dest, $source, FTP_BINARY)) {
            if ($attach['thumb']) {
                if (dftp_put($ftp['connid'], $dest . '.thumb.jpg', $source . '.thumb.jpg', FTP_BINARY)) {
                    if ($ftp['mirror'] != 2) {
                        @unlink($source);
                        @unlink($source . '.thumb.jpg');
                    }
                    return 1;
                } else {
                    dftp_delete($ftp['connid'], $dest);
                }
            } else {
                if ($ftp['mirror'] != 2) {
                    @unlink($source);
                }
                return 1;
            }
        }
        errorlog('FTP', "Upload '{$source}' error.", 0);
        $ftp['mirror'] == 1 && ftpupload_error($source, $attach);
    }
    return 0;
}
コード例 #2
0
function ftpupload($source, $dest, $havethumb = 0)
{
    global $authkey, $ftp;
    if ($ftp['on']) {
        require_once DISCUZ_ROOT . './include/ftp.func.php';
        if (!$ftp['connid']) {
            if (!($ftp['connid'] = dftp_connect($ftp['host'], $ftp['username'], authcode($ftp['password'], 'DECODE', md5($authkey)), $ftp['attachdir'], $ftp['port'], $ftp['ssl']))) {
                return 0;
            }
            $ftp['pwd'] = FALSE;
        }
        $tmp = explode('/', $dest);
        if (count($tmp) > 1) {
            if (!$ftp['pwd'] && !dftp_chdir($ftp['connid'], $tmp[0])) {
                if (!dftp_mkdir($ftp['connid'], $tmp[0])) {
                    errorlog('FTP', "Mkdir '{$ftp['attachdir']}/{$tmp['0']}' error.", 0);
                    return 0;
                }
                if (!function_exists('ftp_chmod') || !dftp_chmod($ftp['connid'], 0777, $tmp[0])) {
                    dftp_site($ftp['connid'], "'CHMOD 0777 {$tmp['0']}'");
                }
                if (!dftp_chdir($ftp['connid'], $tmp[0])) {
                    errorlog('FTP', "Chdir '{$ftp['attachdir']}/{$tmp['0']}' error.", 0);
                    return 0;
                }
                dftp_put($ftp['connid'], 'index.htm', $GLOBALS['attachdir'] . '/index.htm', FTP_BINARY);
            }
            $dest = $tmp[1];
            $ftp['pwd'] = TRUE;
        }
        if (dftp_put($ftp['connid'], $dest, $source, FTP_BINARY)) {
            if ($havethumb) {
                if (dftp_put($ftp['connid'], $dest . '.thumb.jpg', $source . '.thumb.jpg', FTP_BINARY)) {
                    @unlink($source);
                    @unlink($source . '.thumb.jpg');
                    return 1;
                } else {
                    dftp_delete($ftp['connid'], $dest);
                }
            } else {
                @unlink($source);
                return 1;
            }
        }
        errorlog('FTP', "Upload '{$source}' error.", 0);
    }
    return 0;
}
コード例 #3
0
             break;
         case '-3':
             $alertmsg = $lang['settings_attach_remote_pwderr'];
             break;
         case '-4':
             $alertmsg = $lang['settings_attach_remote_ftpoff'];
             break;
         default:
             $alertmsg = '';
     }
 }
 if (!$alertmsg) {
     if (!dftp_mkdir($ftp_conn_id, $testdir)) {
         $alertmsg = $lang['settings_attach_remote_mderr'];
     } else {
         if (!(function_exists('ftp_chmod') && dftp_chmod($ftp_conn_id, 0777, $testdir)) && !dftp_site($ftp_conn_id, "'CHMOD 0777 {$testdir}'") && !@ftp_exec($ftp_conn_id, "SITE CHMOD 0777 {$testdir}")) {
             $alertmsg = $lang['settings_attach_remote_chmoderr'] . '\\n';
         }
         $testfile = $testdir . '/' . $testfile;
         if (!dftp_put($ftp_conn_id, $testfile, DISCUZ_ROOT . './robots.txt', FTP_BINARY)) {
             $alertmsg .= $lang['settings_attach_remote_uperr'];
             dftp_delete($ftp_conn_id, $testfile);
             dftp_delete($ftp_conn_id, $testfile . '.uploading');
             dftp_delete($ftp_conn_id, $testfile . '.abort');
             dftp_rmdir($ftp_conn_id, $testdir);
         } else {
             if (!@readfile($settingsnew['ftp']['attachurl'] . '/' . $testfile)) {
                 $alertmsg .= $lang['settings_attach_remote_geterr'];
                 dftp_delete($ftp_conn_id, $testfile);
                 dftp_rmdir($ftp_conn_id, $testdir);
             } else {
コード例 #4
0
function dftp_chmod($ftp_stream, $mode, $filename)
{
    $mode = intval($mode);
    $filename = wipespecial($filename);
    if (function_exists('ftp_chmod')) {
        return @ftp_chmod($ftp_stream, $mode, $filename);
    } else {
        return dftp_site($ftp_stream, 'CHMOD ' . $mode . ' ' . $filename);
    }
}