Home  >  Article  >  Backend Development  >  PHP-postman uploads images to the server

PHP-postman uploads images to the server

不言
不言Original
2018-04-26 14:39:372322browse

This article introduces the content of PHP-postman uploading images to the server. Now I share it with you. Friends in need can refer to it


1. Postman settings:


PHP-postman uploads images to the server

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 ));
    }
}

3. API description:

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

PHP-postman uploads images to the server

Related recommendations:

postman method of uploading pictures to the server


The above is the detailed content of PHP-postman uploads images to the server. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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