小编Dar*_*ife的帖子

标头下载文件已损坏

我正试图通过我的数据库中的标题下载文件.当我将下载代码更改为使用OOP的下载代码时,我不确定为什么我下载的文件全部损坏但是当我的代码是非OOP时这样做很好.

这是我获取文件ID并调用下载函数的地方:(handleDownload.php)

if (isset($_GET['id'])) {
        $id = $_GET['id'];
        //pump id into function getDBFiles to pull file with matching id
        $fileData = $Download->getDBFiles($id);
        header('Content-Type:"' . $fileData[2]. '"');
        header('Content-Disposition: attachment; filename="' . $fileData[1]. '"'); 
        echo $fileData[0];
        exit;
      }
Run Code Online (Sandbox Code Playgroud)

这是从数据库中提取文件的函数(download.php)

public function getDBFiles($id) {
            global $database;
            $sql = "SELECT * FROM ".self::$table_name." WHERE resume_id ='" . $id . "'";
            $result = $database->query($sql);
            if ($row = $result->fetch_array(MYSQLI_ASSOC)) {  
                $name = $row['resume_title'];
                $type = $row['file_type'];
                $content = $row['resume_data']; //content of file
                //$size = $row['file_size']; //file …
Run Code Online (Sandbox Code Playgroud)

php database oop header-files

8
推荐指数
1
解决办法
526
查看次数

Mime验证php文件上传无效

我正在尝试在将文件上传到数据库之前验证文件的mime类型.但是,我没有从我的程序中获得任何输出.有人可以帮我这个吗?提前致谢 :)

表单句柄代码(handleUpload.php)

<?php
    if (isset($_POST['submit'])) {
        $Upload = new Upload();
        if (function_exists("check_doc_mime")) {
            //validate MIME type
            $validateMime = $Upload->check_doc_mime($_FILES['filename']['tmp_name']);
           if (!$Upload->check_doc_mime($validateMime)) {
                /* Not a MIME type we want on our site, stop here
                 * and return an error message, or just die(); */
                echo "Mime not what we want.";
            } else {
                echo "This is okay";
            }
        } 
    }
?>
Run Code Online (Sandbox Code Playgroud)

函数和数据库操作代码(upload.php)

<?php
    // If it's going to need the database, then it's 
    // probably smart to require it …
Run Code Online (Sandbox Code Playgroud)

html php mysql oop

5
推荐指数
1
解决办法
111
查看次数

标签 统计

oop ×2

php ×2

database ×1

header-files ×1

html ×1

mysql ×1