首頁 >後端開發 >php教程 >postman上傳圖片到伺服器方法

postman上傳圖片到伺服器方法

小云云
小云云原創
2018-03-29 10:29:093619瀏覽

本文主要和大家分享postman上傳圖片到伺服器方法,結合圖文的形式,希望能幫助大家。

1. postman的設定:

postman上傳圖片到伺服器方法

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說明:

請求方式 參數 #是否必須 #參數說明
參數說明

postman上傳圖片到伺服器方法

#POST

uploadpostman上傳圖片到伺服器方法

Y

postman上傳圖片到伺服器方法

########## #1. postman的設定:###############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######所要上傳的檔案#####################

以上是postman上傳圖片到伺服器方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn