zoukankan      html  css  js  c++  java
  • fastdfs API

    注解:

     

    Filename是storage返回的remote_filename

     

    file_id是including group name and filename

     

    group是storage的组名

     

    timestamp是时间戳

     

    local_filename本地文件名

     

    file_ext_name文件扩展名

     

    meta_list详细文件属性列表

     

    tracker_server Fast的服务器地址

     

    storage_server    group地址

     
     

    获取FastDFS的版本:

     

    fastdfs_client_version()

     

    返回值类型:字符串

     
     

    获取错误记录数:

     

    fastdfs_get_last_error_no()

     

    返回值类型:int

     
     

    获取错误信息:

     

    fastdfs_get_last_error_info()

     

    返回值类型:字符串

     
     

    获取产生反偷令牌函数:

     

    fastdfs_http_gen_token(string file_id, int timestamp)

     

    返回值类型:string

    parameters:
     remote_filename: the remote filename (do NOT including group name)
     timestamp: the timestamp (unix timestamp)
    return token string for success, false for error
     

    通过文件名得到文件详细信息:

     

    fastdfs_get_file_info(string group_name, string filename)

     

    返回值类型:array

     

    包括信息:时间戳

     

                         文件大小

     

                         源地址

    parameters:
     group_name: the group name of the file
     remote_filename: the filename on the storage server
    return assoc array for success, false for error. 
     the assoc array including following elements:
      create_timestamp: the file create timestamp (unix timestamp)
      file_size: the file size (bytes)
      source_ip_addr: the source storage server ip address
     
     

    通过文件id获取文件信息:

     

    fastdfs_get_file_info1(string file_id)

     

    返回值类型:array

     

    包括信息:时间戳

     

                         文件大小

     

                         源地址

    parameters:
     file_id: the file id (including group name and filename) or remote filename
    return assoc array for success, false for error. 
     the assoc array including following elements:
      create_timestamp: the file create timestamp (unix timestamp)
      file_size: the file size (bytes)
      source_ip_addr: the source storage server ip address
     

    由主文件名产生从文件名:

     

    string fastdfs_gen_slave_filename(string master_filename, string prefix_name

     

                    [, string file_ext_name])

     

    返回值:字符串

     

    返回信息:从文件名,出错返回error

    parameters:
     master_filename: the master filename / file id to generate 
       the slave filename
     prefix_name: the prefix name  to generate the slave filename
     file_ext_name: slave file extension name, can be null or emtpy 
       (do not including dot)
    return slave filename string for success, false for error
     

    上传本地文件到服务器:

     

    array fastdfs_storage_upload_by_filename(string local_filename

     

             [, string file_ext_name, array meta_list, string group_name,

     

             array tracker_server, array storage_server])

     

    返回值:array

    parameters:
     local_filename: the local filename
     file_ext_name: the file extension name, do not include dot(.)
     meta_list: meta data assoc array, such as
                       array('width'=>1024, 'height'=>768)
     group_name: specify the group name to store the file
     tracker_server: the tracker server assoc array including elements: 
                            ip_addr, port and sock
     storage_server: the storage server assoc array including elements:
                            ip_addr, port and sock
    return assoc array for success, false for error. 
           the returned array includes elements: group_name and filename
     

    上传本地文件到服务器:

     

    string fastdfs_storage_upload_by_filename1(string local_filename

     

             [, string file_ext_name, string meta_list, string group_name,

     

             array tracker_server, array storage_server])

     

    返回值:string

     

    例如:fastdfs_storage-upload_by_filename1("/zxy.jpg", null, array(), null, $tracker, $storage);

    parameters:
     local_filename: the local filename
     file_ext_name: the file extension name, do not include dot(.)
     meta_list: meta data assoc array, such as
                       array('width'=>1024, 'height'=>768)
     group_name: specify the group name to store the file
     tracker_server: the tracker server assoc array including elements: 
                            ip_addr, port and sock
     storage_server: the storage server assoc array including elements:
                            ip_addr, port and sock
    return file_id for success, false for error.
     

    上传文件到存储服务器的缓存。

     

    fastdfs_storage_upload_by_filebuff(string file_buff

     

             [, string file_ext_name, string meta_list, string group_name,

     

             array tracker_server, array storage_server])

     

    返回值:array

    parameters:
     file_buff: the file content
     file_ext_name: the file extension name, do not include dot(.)
     meta_list: meta data assoc array, such as
                       array('width'=>1024, 'height'=>768)
     group_name: specify the group name to store the file
     tracker_server: the tracker server assoc array including elements: 
                            ip_addr, port and sock
     storage_server: the storage server assoc array including elements:
                            ip_addr, port and sock
    return assoc array for success, false for error. 
           the returned array includes elements: group_name and filename
     

    上传本地文件到存储服务器:

     

    fastdfs_storage_upload_appender_by_filename(string local_filename

     

             [, string file_ext_name, array meta_list, string group_name,

     

             array tracker_server, array storage_server])

     

    返回值:array

    parameters:
     local_filename: the local filename
     file_ext_name: the file extension name, do not include dot(.)
     meta_list: meta data assoc array, such as
                       array('width'=>1024, 'height'=>768)
     group_name: specify the group name to store the file
     tracker_server: the tracker server assoc array including elements: 
                            ip_addr, port and sock
     storage_server: the storage server assoc array including elements:
                            ip_addr, port and sock
    return assoc array for success, false for error. 
           the returned array includes elements: group_name and filename
     

    删除storage上的文件:

     

    fastdfs_storage_delete_file(string group_name, string remote_filename

     

             [, array tracker_server, array storage_server])

     

    返回值:boolean

    parameters:
     group_name: the group name of the file
     remote_filename: the filename on the storage server
     tracker_server: the tracker server assoc array including elements: 
                            ip_addr, port and sock
     storage_server: the storage server assoc array including elements:
                            ip_addr, port and sock
    return true for success, false for error
     
     

    删除storage上的文件:

     

    fastdfs_storage_delete_file1(string file_id

     

             [, array tracker_server, array storage_server])

     

    返回值:boolean

    parameters:
     file_id: the file id to be deleted
     tracker_server: the tracker server assoc array including elements: 
                            ip_addr, port and sock
     storage_server: the storage server assoc array including elements:
                            ip_addr, port and sock
    return true for success, false for error
     

    下载文件:(请根据调用情况使用下载函数,url的下载可以直接参考组合url地址)

     

    fastdfs_storage_download_file_to_buff(string group_name,

     

             string remote_filename [, long file_offset, long download_bytes,

     

             array tracker_server, array storage_server])

     

             返回值:string

    parameters:
     group_name: the group name of the file
     remote_filename: the filename on the storage server
     file_offset: file start offset, default value is 0
     download_bytes: 0 (default value) means from the file offset to 
                            the file end
     tracker_server: the tracker server assoc array including elements: 
                            ip_addr, port and sock
     storage_server: the storage server assoc array including elements:
                            ip_addr, port and sock
    return the file content for success, false for error
     

    下载文件:

     

    fastdfs_storage_download_file_to_buff1(string file_id

     

            [, long file_offset, long download_bytes,

     

             array tracker_server, array storage_server])

     

    返回值:string

    parameters:
     file_id: the file id of the file
     file_offset: file start offset, default value is 0
     download_bytes: 0 (default value) means from the file offset to 
                            the file end
     tracker_server: the tracker server assoc array including elements: 
                            ip_addr, port and sock
     storage_server: the storage server assoc array including elements:
                            ip_addr, port and sock
    return the file content for success, false for error
     
     

    下载文件到本地:

     

    fastdfs_storage_download_file_to_file(string group_name,

     

             string remote_filename, string local_filename [, long file_offset,

     

             long download_bytes, array tracker_server, array storage_server])

     

    返回值:boolean

    parameters:
     group_name: the group name of the file
     remote_filename: the filename on the storage server
     local_filename: the local filename to save the file content
     file_offset: file start offset, default value is 0
     download_bytes: 0 (default value) means from the file offset to 
                            the file end
     tracker_server: the tracker server assoc array including elements: 
                            ip_addr, port and sock
     storage_server: the storage server assoc array including elements:
                            ip_addr, port and sock
    return true for success, false for error
     

    设置文件元数据属性:

     

    fastdfs_storage_set_metadata(string group_name, string remote_filename,

     

             array meta_list [, string op_type, array tracker_server,

     

             array storage_server])

     

    返回值:boolean

    parameters:
     group_name: the group name of the file
     remote_filename: the filename on the storage server
     meta_list: meta data assoc array to be set, such as
                       array('width'=>1024, 'height'=>768)
     op_type: operate flag, can be one of following flags:
      FDFS_STORAGE_SET_METADATA_FLAG_MERGE: combined with the old meta data
      FDFS_STORAGE_SET_METADATA_FLAG_OVERWRITE: overwrite the old meta data
     tracker_server: the tracker server assoc array including elements: 
                            ip_addr, port and sock
     storage_server: the storage server assoc array including elements:
                            ip_addr, port and sock
    return true for success, false for error
     

    设置文件元数据:

     

    fastdfs_storage_get_metadata(string group_name, string remote_filename

     

             [, array tracker_server, array storage_server])

     

    返回值:boolean

    parameters:
     group_name: the group name of the file
     remote_filename: the filename on the storage server
     tracker_server: the tracker server assoc array including elements: 
                            ip_addr, port and sock
     storage_server: the storage server assoc array including elements:
                            ip_addr, port and sock
    return assoc array for success, false for error
           returned array like: array('width' => 1024, 'height' => 768)
     
     

    连接服务器:

     

    fastdfs_connect_server(string ip_addr, int port)

     

    返回值:array: 

        Ip地址
        Port
    parameters:
     ip_addr: the ip address of the server
     port: the port of the server
    return assoc array for success, false for error
     
     
    断开服务器连接:
     
    fastdfs_disconnect_server(array server_info)
     
    返回值:boolean
    parameters:
     server_info: the assoc array including elements:
                         ip_addr, port and sock
    return true for success, false for error
     
     
     
     
    状态测试:(主要测试storage的状态)
     
    fastdfs_active_test(array server_info)
     
    返回值:boolean
    parameters:
     server_info: the assoc array including elements:
                         ip_addr, port and sock, sock must be connected
    return true for success, false for error
     
     
    获取一个tracker server连接:
     
    fastdfs_tracker_get_connection()
     
    返回值:boolean
    return assoc array for success, false for error
           the assoc array including elements: ip_addr, port and sock
     
     
    连接到所有的tracker
     
    fastdfs_tracker_make_all_connections()
     
    返回值:boolean
    return true for success, false for error
     
     
    关闭所有的tracker连接:
     
    fastdfs_tracker_close_all_connections()
     
    返回值:boolean
    return true for success, false for error
     
     
     
     
    获得小组统计信息
     
    fastdfs_tracker_list_groups([string group_name, array tracker_server])
     
    返回值:array
    parameters:
     group_name: specify the group name, null or empty string means all groups
     tracker_server: the tracker server assoc array including elements:
                            ip_addr, port and sock
    return index array for success, false for error, each group as a array element
     
     
    获取storage信息
     
    fastdfs_tracker_query_storage_store([string group_name,
     
                       array tracker_server])
     
    返回值:array
    parameters:
     group_name: specify the group name
     tracker_server: the tracker server assoc array including elements:
                            ip_addr, port and sock
    return assoc array for success, false for error. the assoc array including
           elements: ip_addr, port, sock and store_path_index
     
     
    连接所有的tracker
     
    fastdfs_tracker_make_all_connections()
     
    返回值:boolean
    return true for success, false for error

     
    获取存储服务器的信息:
     
    fastdfs_tracker_query_storage_store([string group_name,
     
                       array tracker_server])
     
    返回值:array
    parameters:
     group_name: specify the group name
     tracker_server: the tracker server assoc array including elements:
                            ip_addr, port and sock
    return assoc array for success, false for error. the assoc array including
           elements: ip_addr, port, sock and store_path_index
     
     
    获取上传服务器的信息列表:
     
    fastdfs_tracker_query_storage_store_list([string group_name,
     
                       array tracker_server])
     
    返回值:array
    parameters:
     group_name: specify the group name
     tracker_server: the tracker server assoc array including elements:
                            ip_addr, port and sock
    return indexed storage server array for success, false for error.
           each element is an ssoc array including elements: 
           ip_addr, port, sock and store_path_index
     
     
    删除一个存储服务器:
     
    fastdfs_tracker_delete_storage(string group_name, string storage_ip)
     
    返回值:boolean
    parameters:
     group_name: the group name of the storage server
     storage_ip: the ip address of the storage server to be deleted
    return true for success, false for error
     
     
    实例:
    1.       上传一个文件:
    复制代码
    <?php
    $tracker = fastdfs_tracker_get_connection(); var_dump($tracker);
    if (!fastdfs_active_test($tracker)) {   error_log("errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info());
      exit(1); } $storage = fastdfs_tracker_query_storage_store();
    if (!$storage) {   error_log("errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info());   exit(1); } $file_info = fastdfs_storage_upload_by_filename("/zxy.jpg", null, array(), null, $tracker, $storage);
    复制代码

    2.       下载一个文件

    复制代码
    <?php
    $group_name="group3";
    $filename="M00/00/00/wKgAUE5zkhH8yBZwAAGH3hvfjJA398.jpg";
    $file_id="group3/M00/00/00/wKgAUE5zkhH8yBZwAAGH3hvfjJA398.jpg";
    $timestamp="2011-09-17 02:14:41";
    fastdfs_storage_download_file_to_file($group_name,$filename, "test.jpg");
    复制代码

    3.       删除一个文件

    复制代码
    <?php

    $group_name="group3";
    $filename="M00/00/00/wKgAUE5zkhH8yBZwAAGH3hvfjJA398.jpg";
    echo fastdfs_storage_delete_file($group_name, $filename);
    复制代码
  • 相关阅读:
    【6.29】数组和方法
    【6.28】判断和循环
    【6.27】两个数交换的4种方法
    NodeJS学习笔记
    准备使用马克飞象写博客
    前端基础
    学习笔记
    数据结构 — Java链表
    Java 日期类型与字符串的相互转换
    Scala(一)基础
  • 原文地址:https://www.cnblogs.com/yipianchuyun/p/15450111.html
Copyright © 2011-2022 走看看