Postman upload pictures to server method

小云云
Release: 2023-03-22 15:42:02
Original
3587 people have browsed it

This article mainly shares with you the postman method of uploading pictures to the server, combined with the form of pictures and texts, I hope it can help everyone.

1. Postman settings:

Postman upload pictures to server method

2. PHP code:

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 ));
    }
}
Copy after login
Copy after login

3. API description:

Request methodParametersIs it required?Parameter description
POSTuploadYFile to be uploaded

Postman upload pictures to server method

1. Postman settings:

Postman upload pictures to server method

2. PHP code:

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 ));
    }
}
Copy after login
Copy after login

3. API description:

Request method Parameters Is it required? Parameter description
POST upload Y File to be uploaded

Postman upload pictures to server method

The above is the detailed content of Postman upload pictures to server method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!