如何通过PHP从Flutter App上传照片到服务器?

How to upload photo from Flutter App to server via PHP?

你好,我正在尝试将我的照片从 flutter 应用程序上传到服务器,当我在 Xampp 上使用时它可以工作,但是当我尝试更改为真实服务器时它没有工作我想要知道为什么

这是我的API上传照片到服务器

<?php
error_reporting(E_ERROR | E_PARSE);

// Response object structure
$response = new stdClass;
$response->status = null;
$response->message = null;

// Uploading file
$destination_dir = "Foodpic/";
$base_filename = basename($_FILES["file"]["name"]);
$target_file = $destination_dir . $base_filename;

if(!$_FILES["file"]["error"])
{
    if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {        
        $response->status = true;
        $response->message = "File uploaded successfully";

    } else {

        $response->status = false;
        $response->message = "File uploading failed";
    }    
} 
else
{
    $response->status = false;
    $response->message = "File uploading failed";
}

header('Content-Type: application/json');
echo json_encode($response);

这是我在应用程序中的代码

  Future<Null> uploadFoodPhoto() async {
String url = '${Myconstant().domain}/API/foodImg.php';
Random x = Random();
int i = x.nextInt(999999999);
String lmgName = 'Food$i.jpg';
try {
  Map<String, dynamic> map = Map();
  map['file'] = await MultipartFile.fromFile(file.path, filename: lmgName);
  FormData formData = FormData.fromMap(map);
  await Dio().post('$url', data: formData).then((value) {
    print('Res = $value');
    urlImage = '/Buudeli/Foodpic/$lmgName';
    print('ImageUrl = ${Myconstant().domain}$urlImage');
    insertToDB();
  });
} catch (e) {}}

Xampp 和真实服务器使用相同的代码,但不知道为什么它不起作用。总是说"Res = {"status":false,"message":"文件上传失败"" 如果我遗漏了什么,请告诉我
Ps。我的英语不好对不起,如果你不明白什么请让我解释

好的我已经知道我想念什么了....我忘了更改服务器上的 public 权限....现在一切正常 xD