Php android图像文件上载成功运行,但未将图像移动到文件夹
我在android中有以下代码Php android图像文件上载成功运行,但未将图像移动到文件夹,php,android,json,Php,Android,Json,我在android中有以下代码 String uploadId = UUID.randomUUID().toString(); //Creating a multi part request new MultipartUploadRequest(getContext(), uploadId, url_upload_cert) .addFileToUpload(path, "pdf") //Adding fil
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文件夹中的图像时,它不在那里
当我使用postman测试脚本时也会发生同样的情况
我在windows上使用wamp服务器。
原因可能是什么?检查文件夹的写入权限 例如,在Linux中,在文件夹上方的某个级别,您可以使用以下命令:
sudo chmod -R 777 <your-folder-name>
具有打开的值
如果这不起作用,您可以检查默认的php.ini文件,并尝试用该文件替换您的php.ini文件。执行
var\u转储($\u文件)
检查您得到了什么。在andoid中,您将其命名为“pdf”,在php中,您在与postman测试时尝试获取“jpg”,我使用相同的名称jpg只是为了检查名称是否存在问题,因为我在windows中,在哪里可以找到文件php.ini请?@Berniegach这取决于您使用的服务器,例如,如果将XAMPP与默认安装一起使用:您应该在C:\XAMPP\php\php.ini中找到该文件。您还可以在php文件上运行代码“”,如本问题所示:查看您的文件在行的何处('加载的配置文件').php.ini中的file_uploads变量正在检查上载文件夹“android/”的权限,并为每个人设置写入和读取。我正在将写入属性更改为在file属性的安全选项中勾选,但General上的属性一直显示为只读
file_uploads = On