0

我的上传/下载过程有一些问题。我的文件作为 BLOB 插入到 mysql 中,但是下载时它会抓取调用 php 页面的 html 标记。在插入数据库之前,我是否需要将上传的文件移动到临时目录?

编辑:当前的 upload.php 文件。仍然获得 html 内容而不是实际文件本身,它仍然被正确命名。

           <?php
                    // Make sure an ID was passed DOWNLOAD HANDLER *******
if(isset($_GET['id'])) {
// Get the ID
    $id = intval($_GET['id']); var_dump($id);


    require_once ('../mysqli_connect.php'); //Connect to the db



        // Fetch the file information
        $downloadq = "
            SELECT `file_type`, `size`, `title`, 'content', 'upload_id'
            FROM `upload`
            WHERE `upload_id` =".$id;
        $result = mysqli_query ($dbc, $downloadq); // Run the query


        if($result) {
            // Make sure the result is valid
            if (mysqli_num_rows($result) > 0) {
            // Get the row
                $row = mysqli_fetch_assoc($result);
                //var_dump($row);

                // Print headers
                header("Content-Type: application/msword");
                header("Content-Length: ". $row['size']);
               header("Content-Disposition: attachment; filename=". $row['title']);
               header("Content-Transfer-Encoding: binary");


                // Print data
                echo (stripslashes($row['content']));


            }
            else {
                echo 'Error! No such ID.';
            }

            // Free the mysqli resources
            mysqli_free_result($result);
        }
        else {
            echo "Error! Query failed: <pre>{$dbc->error}</pre>";
        }
        mysqli_close($dbc);
}
                ?>
4

2 回答 2

0
CREATE TABLE `file` (
    `id`        Int Unsigned Not Null Auto_Increment,
    `name`      VarChar(255) Not Null Default 'Untitled.txt',
    `mime`      VarChar(50) Not Null Default 'text/plain',
    `size`      BigInt Unsigned Not Null Default 0,
    `data`      MediumBlob Not Null,
    `created`   DateTime Not Null,
    PRIMARY KEY (`id`)
)
于 2012-05-28T11:30:27.910 回答
0

你可以试试这个。在以下行之后

echo (stripslashes($row['content']));

再写一行

exit;

也许这会对你有所帮助。

于 2012-05-23T15:41:33.660 回答