PHP-postman上传图片到服务器

1. postman的设置:

PHP-postman上传图片到服务器_第1张图片

2. PHP代码:

public function byte(){
    $base_path = "./uploads/"; //存放目录
    if(!is_dir($base_path)){
        mkdir($base_path,0777,true);
    }
    $target_path = $base_path . basename ( $_FILES ['upload'] ['name'] );
    if (move_uploaded_file ( $_FILES ['upload'] ['tmp_name'], $target_path )) {
        $info['mess'] = 'ok';
        //$info['flag'] = 0;
        exit(json_encode($info));
    } else {
        $array = array (
            "flag" => 0,
            "mess" => "There was an error uploading the file, please try again!" . $_FILES ['upload'] ['error']
        );
        exit(json_encode ( $array ));
    }
}

3. api说明:

请求方式 参数 是否必须 参数说明
POST upload Y 所要上传的文件

PHP-postman上传图片到服务器_第2张图片

你可能感兴趣的:(PHP,PHP,文件上传,api)