コード例 #1
0
function plugins_releasemgt_file_add($p_tmp_file, $p_file_name, $p_file_type, $p_project_id, $p_version_id, $p_description, $p_file_error)
{
    if (php_version_at_least('4.2.0')) {
        switch ((int) $p_file_error) {
            case UPLOAD_ERR_INI_SIZE:
            case UPLOAD_ERR_FORM_SIZE:
                trigger_error(ERROR_FILE_TOO_BIG, ERROR);
                break;
            case UPLOAD_ERR_PARTIAL:
            case UPLOAD_ERR_NO_FILE:
                trigger_error(ERROR_FILE_NO_UPLOAD_FAILURE, ERROR);
                break;
            default:
                break;
        }
    }
    if ('' == $p_tmp_file || '' == $p_file_name) {
        trigger_error(ERROR_FILE_NO_UPLOAD_FAILURE, ERROR);
    }
    if (!is_readable($p_tmp_file)) {
        trigger_error(ERROR_UPLOAD_FAILURE, ERROR);
    }
    if (!plugins_releasemgt_file_is_name_unique($p_file_name, $p_project_id, $p_version_id)) {
        trigger_error(ERROR_DUPLICATE_FILE, ERROR);
    }
    $c_version_id = db_prepare_int($p_version_id);
    $c_project_id = db_prepare_int($p_project_id);
    $c_file_type = db_prepare_string($p_file_type);
    $c_title = db_prepare_string($p_file_name);
    $c_desc = db_prepare_string($p_description);
    $t_file_path = dirname(plugin_config_get('disk_dir', PLUGINS_RELEASEMGT_DISK_DIR_DEFAULT) . DIRECTORY_SEPARATOR . '.') . DIRECTORY_SEPARATOR;
    $c_file_path = db_prepare_string($t_file_path);
    $c_new_file_name = db_prepare_string($p_file_name);
    $t_file_hash = $p_version_id . '-' . $t_project_id;
    $t_disk_file_name = $t_file_path . plugins_releasemgt_file_generate_unique_name($t_file_hash . '-' . $p_file_name, $t_file_path);
    $c_disk_file_name = db_prepare_string($t_disk_file_name);
    $t_file_size = filesize($p_tmp_file);
    if (0 == $t_file_size) {
        trigger_error(ERROR_FILE_NO_UPLOAD_FAILURE, ERROR);
    }
    $t_max_file_size = (int) min(ini_get_number('upload_max_filesize'), ini_get_number('post_max_size'), config_get('max_file_size'));
    if ($t_file_size > $t_max_file_size) {
        trigger_error(ERROR_FILE_TOO_BIG, ERROR);
    }
    $c_file_size = db_prepare_int($t_file_size);
    $t_method = plugin_config_get('upload_method', PLUGINS_RELEASEMGT_UPLOAD_METHOD_DEFAULT);
    switch ($t_method) {
        case FTP:
        case DISK:
            file_ensure_valid_upload_path($t_file_path);
            if (!file_exists($t_disk_file_name)) {
                if (FTP == $t_method) {
                    $conn_id = plugins_releasemgt_file_ftp_connect();
                    file_ftp_put($conn_id, $t_disk_file_name, $p_tmp_file);
                    file_ftp_disconnect($conn_id);
                }
                if (!move_uploaded_file($p_tmp_file, $t_disk_file_name)) {
                    trigger_error(FILE_MOVE_FAILED, ERROR);
                }
                chmod($t_disk_file_name, 0644);
                $c_content = '';
            } else {
                trigger_error(ERROR_FILE_DUPLICATE, ERROR);
            }
            break;
        case DATABASE:
            $c_content = db_prepare_string(fread(fopen($p_tmp_file, 'rb'), $t_file_size));
            break;
        default:
            trigger_error(ERROR_GENERIC, ERROR);
    }
    $t_file_table = plugin_table('file');
    $query = "INSERT INTO {$t_file_table}\n\t\t\t\t\t\t(project_id, version_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content)\n\t\t\t\t\t  VALUES\n\t\t\t\t\t\t({$c_project_id}, {$c_version_id}, '{$c_title}', '{$c_desc}', '{$c_disk_file_name}', '{$c_new_file_name}', '{$c_file_path}', {$c_file_size}, '{$c_file_type}', '" . date("Y-m-d H:i:s") . "', '{$c_content}')";
    db_query($query);
    $t_file_id = db_insert_id();
    return $t_file_id;
}
コード例 #2
0
ファイル: download.php プロジェクト: jhron/mantis-releasemgt
    // get UTF8 filenames to work with the file download dialog. Chrome
    // behaves in the same was as Internet Explorer in this respect.
    // See http://greenbytes.de/tech/tc2231/#attwithfnrawpctenclong
    header('Content-Disposition:' . $t_disposition . ' filename="' . $t_filename . '"');
} else {
    // For most other browsers, we can use this technique:
    // http://greenbytes.de/tech/tc2231/#attfnboth2
    header('Content-Disposition:' . $t_disposition . ' filename*=UTF-8\'\'' . $t_filename . '; filename="' . $t_filename . '"');
}
header('Content-Length: ' . $v_filesize);
header('Content-Type: ' . $v_file_type);
switch (plugin_config_get('upload_method', PLUGINS_RELEASEMGT_UPLOAD_METHOD_DEFAULT)) {
    case DISK:
        if (file_exists($v_diskfile)) {
            readfile($v_diskfile);
        }
        break;
    case FTP:
        if (file_exists($v_diskfile)) {
            readfile($v_diskfile);
        } else {
            $ftp = plugins_releasemgt_file_ftp_connect();
            file_ftp_get($ftp, $v_diskfile, $v_diskfile);
            file_ftp_disconnect($ftp);
            readfile($v_diskfile);
        }
        break;
    default:
        echo $v_content;
}
html_page_bottom();