android - 如何在 MySQL 上从 Android (Java) 下载 PDF
问题描述
<?php
// Check if a file has been uploaded
if (isset($_FILES['uploaded_file'])) {
// Make sure the file was sent without errors
if ($_FILES['uploaded_file']['error'] == 0) {
// Connect to the database
$dbLink = new mysqli('localhost', 'root', '', 'test');
if (mysqli_connect_errno()) {
die("MySQL connection failed: " . mysqli_connect_error());
}
// Gather all required data
$name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']);
$mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
$data = $dbLink->real_escape_string(file_get_contents($_FILES['uploaded_file']['tmp_name']));
$size = intval($_FILES['uploaded_file']['size']);
// Create the SQL query
$query = "
INSERT INTO `file` (
`name`, `mime`, `size`, `data`, `created`
)
VALUES (
'{$name}', '{$mime}', {$size}, '{$data}', NOW()
)";
// Execute the query
$result = $dbLink->query($query);
// Check if it was successfull
if ($result) {
echo 'Success! Your file was successfully added!';
} else {
echo 'Error! Failed to insert the file' . "<pre>{$dbLink->error}</pre>";
}
} else {
echo 'An error accured while the file was being uploaded. ' . 'Error code: ' . intval($_FILES['uploaded_file']['error']);
}
// Close the mysql connection
$dbLink->close();
} else {
echo 'Error! A file was not sent!';
}
// Echo a link back to the main page
echo '<p>Click <a href="file.html">here</a> to go back</p>';
?>
我使用上面的代码使用php,html在我的mysql数据库上上传了一个文件。我想在我的安卓应用上下载这个文件。我对这个android的东西很空白。我最近刚刚使用 mysql 数据库进行了登录活动jdbc
,为此我使用了驱动程序。谁能指导我如何使用android应用下载上述上传的文件?
解决方案
嗨,兄弟,您可以使用 android 的 DownloadService 下载此 pdf。您只需要服务器上文件的位置。这是代码的链接
推荐阅读
- java - 将数组和其他内容传递给 var args
- amazon-web-services - AWS elasticbeanstalk 100 % of cpu is in use 降级
- python - 具有对数频率轴的 scipy 频谱图?
- javascript - 如何使用JS在固定宽度div的末尾自行检测一行上的“孤立”单词?
- json - 无法使用 POSTMAN 从站点获得响应
- reactjs - 访问除根以外的任何 URI 导致 404 - nginx
- c# - 将下一行中的新记录添加到 C# 中的现有 excel 文件中
- php - 将curl与http身份验证一起使用时如何修复需要身份验证的错误401
- reactjs - `height:'100%', width:'100%'`与`Flex:1`之间的区别
- google-chrome-extension - 在 Chrome/Firefox 扩展中加载 Javascript 之前将 HTML 插入页面