【问题标题】:How can I download PDF from Android (Java) on MySQL如何在 MySQL 上从 Android (Java) 下载 PDF
【发布时间】:2019-05-03 03:19:23
【问题描述】:
<?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 mysql pdf


    【解决方案1】:

    你好兄弟,你可以使用android的DownloadService下载这个pdf。你只需要服务器上文件的位置。This is the link of the code

    【讨论】:

    • 嘿,谢谢 Jawwad... 你能告诉我当我在 xampp mysql 上上传文件时如何知道文件的 url ....
    • 如果您使用的是本地主机,请在此处使用您的文件夹的localhost/<Directory>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-23
    • 2011-09-16
    • 2018-06-08
    • 1970-01-01
    相关资源
    最近更新 更多