Android图像文件上传成功运行,但图像未移动到文件夹



我在安卓上有以下代码

String uploadId = UUID.randomUUID().toString();
//Creating a multi part request
new MultipartUploadRequest(getContext(), uploadId, url_upload_cert)
.addFileToUpload(path, "pdf") //Adding file
.addParameter("name", name) //Adding text parameter to the request
.setNotificationConfig(new UploadNotificationConfig())
.setMaxRetries(2)
.startUpload();

和在 PHP 中

<?php
//importing dbDetails file
require_once __DIR__ . '/db_connect.php';
//this is our upload folder
$upload_path = 'android/';
//Getting the server ip
$server_ip = gethostbyname(gethostname());
//creating the upload url
//$upload_url = 'http://'.$server_ip.'/pavo_project/'.$upload_path;
$upload_url='/src';
//response array
$response = array();

if($_SERVER['REQUEST_METHOD']=='POST'){
//checking the required parameters from the request
if(isset($_POST['name']) and isset($_FILES['jpg']['name'])){
// connecting to db
$db = new DB_CONNECT();
//getting name from the request
$name = $_POST['name'];
//getting file info from the request
$fileinfo = pathinfo($_FILES['jpg']['name']);
//getting the file extension
$extension = $fileinfo['extension'];
//file url to store in the database
$file_url = $upload_url . $name . '.' . $extension;
//file path to upload in the server
$file_path = $upload_url . $name . '.'. $extension;
//trying to save the file in the directory
try{
//saving the file
move_uploaded_file($_FILES['jpg']['tmp_name'],$file_path);
}catch(Exception $e){
$response['error']=true;
$response['message']=$e->getMessage();
} 
//closing the connection
// mysqli_close($db);
}else{
$response['error']=true;
$response['message']='Please choose a file';
}
//displaying the response
echo json_encode($response);
}
?>

当我运行 android 代码时,它成功运行没有错误,但是当我检查 src 文件夹中的图像时,它不存在 当我使用邮递员测试脚本时也会发生同样的事情 我在窗口上使用 wamp 服务器。 可能是什么原因导致这种情况?

检查文件夹的写入权限。

例如,在 Linux 中,您的文件夹上方的级别您可以使用以下命令:

sudo chmod -R 777 <your-folder-name>

这可能会让 php 代码将文件保存在其中,因为它将授予每个用户写入/读取/删除的权限。

你也可以检查php.ini文件,并检查该行是否:

file_uploads = On

具有"打开">

如果这不起作用,您可以检查默认的 php.ini 文件,并尝试用该文件替换您的php.ini文件。

最新更新