【发布时间】:2021-03-30 19:20:03
【问题描述】:
我想问如何使用 post 方法将图像文件发布到 MySQL?因为我所做的只是上传文件路径而不是图像。
我的发帖请求:
Future addProduct() async{
var url = 'http://10.0.2.2/foodsystem/addproduct.php';
http.post(url, body: {
"productname": controllerName.text,
"productprice": controllerPrice.text,
"producttype": controllerType.text,
"product_owner": globals.userId,
"image": _image.path,
//"image": _image.path.split('/').last,
});
我的 PHP 代码:
<?php
include 'conn.php';
$product_owner = $_POST['product_owner'];
$productname = $_POST['productname'];
$productprice = $_POST['productprice'];
$producttype = $_POST['producttype'];
$image = $_POST['image'];
//$realImage = base64_decode($image);
$connect->query("INSERT INTO product (product_name, product_price, product_type, product_owner, image) VALUES
('".$productname."','".$productprice."','".$producttype."','".$product_owner."','".$image."')")
?>
我的 MySQL 表
【问题讨论】: