从Blob下载文档

时间:2017-05-31 10:23:27

标签: php mysql mysqli blob

我可以使用mysql blob(msword或pdf)成功上传文档。现在我需要帮助下载它。

这是我的下载按钮代码。

<form id="specificationdownload">
        <input type="hidden" name="cusid" id="cusid" value = "<?php echo $row['id_stk']?>">
        <button class="btn btn-success" name="downloadspec" type="submit">Download </button>
</form>

这是我处理下载按钮表格的Ajax代码

//Specification download 
 $("form#specificationdownload").on("submit",function(e){ 
 e.preventDefault(); 
     jQuery.ajax({
     url: "../data/stock.php?action=stock-specification-download",
     type: "POST",           
     data: new FormData(this), 
     processData: false, 
    contentType: false,
    success: function(data, textStatus, jqXHR) {  
    console.log(2);
    var filter = "<?php echo $id_stc ?>";
    var tab_content_to_change = "#stock-sub-list";
    jQuery(tab_content_to_change).load('/tasks/stock/stock-list.php?filter='+filter);
  },
    error: function(jqXHR, textStatus, errorThrown){

    //Display error message to user
    alert("An error occured when saving the data");
  }
 });
 });

这是我的行动

     $CustomerID = $_POST['cusid'];

    if(isset( $CustomerID )) 
    {

     //Query
    $prepare_query = "SELECT specificationsheet_name_stk,specificationsheet_type_stk,specificationsheet_size_stk, specificationsheet_stk FROM stock_stk 
    WHERE id_stk ='$CustomerID';";
    $result = mysqli_query($mysqli_scs, $prepare_query);

    $row =  mysqli_fetch_array ($result);
    //die(var_dump($row));

    header("Content-length:" .$row['specificationsheet_size_stk']);
    header("Content-type:" .$row['specificationsheet_type_stk']);
    header("Content-Disposition: attachment; filename=".$row['specificationsheet_name_stk']);
    return $row['specificationsheet_stk'];
    exit;
    }

问题是当我点击&#34;下载&#34;按钮,文件没有下载。如果我var_Dump $row,它会使用右键转储数组,因此对象就在那里,但不会打印。

任何人都知道我做错了什么。

谢谢。

0 个答案:

没有答案