php - 通过 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;
解决方案
推荐阅读
- php - array_pop 删除数组中的对象
- java - 2 个外部 Maven 依赖项没有限定类型的 bean
- python - 订阅多个主题 Asyncio_mqtt
- postgresql - PostgreSQL 中从字符串转换为 uuid 的迁移
- javascript - 如果页面关闭不正确或转到 react js 中的另一个组件,如何起草数据?
- sql - 将 SQL/SAS 表行转置为多列
- node.js - 对使用传递空值的节点 js 部署的 ml 模型同时进行多个请求
- loops - 如何在列表中找到与同一列表中先前选择的项目相似的下一个项目?Python
- javascript - “TypeError:无法读取未定义的属性'forEach'”在NodeJS中
- python - TensorFlow 不需要的子图