从mysql android下载pdf

z5btuh9x  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(276)
<?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>';
?>

我使用上面的代码在mysql数据库中使用php、html上传了一个文件。我想在我的android应用程序上下载这个文件。我对安卓这个东西完全不了解。我最近刚刚使用mysql数据库做了一个登录活动,我使用 jdbc 为了这个目的。有谁能指导我如何使用android应用程序下载上面上传的文件吗?

zfycwa2u

zfycwa2u1#

嗨,兄弟,你可以使用android的下载服务下载这个pdf文件。你只需要服务器上文件的位置。这是代码的链接

相关问题