简体   繁体   English

如何使用没有html的Mysql blob下载文件

[英]How to download file with Mysql blob without html

I am having a problem with downloading blob file, my sql query returns perfect result but while im downloading i am getting download page's html code in it not the blob data. 我有一个下载blob文件的问题,我的SQL查询返回完美的结果,但我下载时,我得到下载页面的HTML代码,而不是blob数据。 It is important to say that im using wordpress and writing a custom funtion for that. 重要的是要说我使用wordpress并为此编写自定义功能。 now if i remove the get_header() from page file the output returns perfectly but if the get_header present it returns the htmls. 现在,如果我从页面文件中删除get_header(),则输出完全返回,但如果get_header存在,则返回htmls。 now how can i get rid of it? 现在我怎么能摆脱它?

here are my download function: 这是我的下载功能:

   foreach($search_order as $order)
    {   

    header();
    $file_name = 'Li_'. $random_number . '.mg';
    $mimetype = 'application/octet-stream';
    $filedata = $order->data;
    header("Content-length: ".strlen($filedata));
    header("Content-type:" .$mimetype);
    header("Content-disposition: download; filename=" .$file_name);     

    }

    echo $filedata;

and in page.php i put this to call the function: 并在page.php我把它调用函数:

downloadFile($order_id);

echo "<td><a href=?id=" . $search->order .">download file</a>";

Thanks 谢谢

OK

I found the answer, you have to call the function before the get_header(); 我找到了答案,你必须在get_header()之前调用函数; but my analysis states that, if you want to download pdf or any other file you have call that before the tag to get rid of the html injection. 但我的分析表明,如果你想下载pdf或任何其他你在标签之前调用的文件来摆脱html注入。

hope this helps to others 希望这有助于他人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM