首页 > 解决方案 > 通过 Post 方法将图像从 android 发送到 PHP 并将其保存在服务器中?

问题描述

我编写了一个 android 应用程序,应该将配置文件图像发送到服务器并将其保存在那里......我正在使用 gotev android 上传服务,它运行良好并将我的图像发送到服务器,但我的问题是在我的服务器端不能在我的目标文件夹中移动或复制它......我的服务器中的 PHP 是:

<?php 
$isSuccess = false ;
$uploaddir = 'profiles/';
$uploadfile = $uploaddir . basename($_FILES['profile']['name']);

if ($_FILES["profile"]["error"] > 0) {
    echo "Error: " . $_FILES["profile"]["error"] . "<br>";
} else {
    $myObj->name = $_FILES['profile']['name'];
    $myObj->type = $_FILES['profile']['type'];
    $myObj->size = ($_FILES["profile"]["size"] / 1024);
    $myObj->storedin = $_FILES['profile']['tmp_name'];
    $myObj->username = $_POST['username'];
    if(isset($_FILES['profile']['name']) && isset($_POST['username'])){
        try{
            copy($_FILES['profile']['tmp_name'],$uploadfile );
            //$movesuc = move_uploaded_file($_FILES['profile']['tmp_name'],$uploadfile);
            //$myObj->mvesuc = $movesuc;
            $myObj->error = false;
            $isSuccess = true;
            $myObj->message = 'File uploaded successfully';
        }catch(Exception $e){
            $myObj->error = true;
            $myObj->message = 'Could not upload file';
        }
    }else{
        $myObj->error = true;
        $myObj->message = "Required params not available";
    }
}
//header('Content-Type: application/json');
$myObj->isSuccess = $isSuccess;
$myJSON = json_encode($myObj);
echo $myJSON;

标签: phpandroidkotlinplesk

解决方案


推荐阅读