restapi php upload image在postman中不起作用,方法“post”

g6baxovj  于 2021-06-17  发布在  Mysql
关注(0)|答案(0)|浏览(235)

我已经按照教程“安卓上传图像使用安卓上传服务”,但它不工作。
我已经实现了 Postman 软件,但仍然没有回应?
这是我的代码版本:
数据库配置.php

<?php
/**
 * Created by PhpStorm.
 * User: Heri Prastio
 * Date: 27/12/2018
 * Time: 21:40
 */
define('HOST','localhost');
define('USER', 'root');
define('PASS', '');
define('DB','db_images');
?>

上传.php

<?php
/**
 * Created by PhpStorm.
 * User: Heri Prastio
 * Date: 27/12/2018
 * Time: 21:43
 */
//Importing dbConfig.php
require_once 'dbConfig.php';

//My folder uploads images
$upload_path = 'uploads/';

$server_ip = gethostbyname(gethostname());

$upload_url = 'http://' . $server_ip . '/AndroidImageUpload/' . $upload_path;

$respon = array();

//I don't understand this part of the code
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_POST['name']) and isset($_FILES['image']['name'])) {
        $con = mysqli_connect(HOST, USER, PASS, DB) or die("Unable to connect");

        $name = $_POST['name'];
        $fileinfo = pathinfo($_FILES['image']['name']);

        $extension = $fileinfo['extension'];

        $file_url = $upload_url . getFileName() . '.' . $extension;
        $file_path = $upload_path . getFileName() . '.' . $extension;

        try {
            move_uploaded_file($_FILES['image']['tmp_name'], $file_path);
            $sql = "INSERT INTO images_table('id','url','name') values (NULL , $file_url, '$name');";

这是完整的源代码链接:(upload.php)
这是一个执行 Postman 软件的图片,没有回应。在此处输入图像描述

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题