gpt4 book ai didi

android - 如何在 MySQL 上从 Android (Java) 下载 PDF

转载 作者:行者123 更新时间:2023-11-29 16:36:46 24 4
gpt4 key购买 nike

<?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 应用程序上下载这个文件。我对android这个东西很空白。我最近刚刚使用 mysql 数据库进行了登录 Activity ,并为此使用了 jdbc 驱动程序。谁能指导我如何使用 Android 应用程序下载上述上传的文件?

最佳答案

嗨,兄弟,您可以使用 android 的 DownloadService 下载此 pdf。您只需要该文件在服务器上的位置即可。 This is the link of the code

关于android - 如何在 MySQL 上从 Android (Java) 下载 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53566501/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com