在php而不是下载csv文件,它在浏览器中打开 [英] In php Instead of downloading csv file it gets open in the browser
问题描述
我正在尝试通过浏览器下载CSV文件。脚本部分工作,因为到目前为止,我设法在屏幕上显示CSV,但是下载没有开始。
I'm trying to download a CSV file through the browser. The script is partially working, because so far I managed to display the CSV on screen, but the download is not starting.
这是我迄今为止所尝试的:如果(isset($ currency)){
header(Content-Type:application / csv); p>
Here is what i tried so far:
if(isset($currency)) {
header("Content-Type: application/csv");
header("Content-Disposition: attachment;Filename=Pricelogs.csv");
ob_clean();
$filename = "/tmp/".uniqid().".csv";
exportCSVFile($filename, $currency, $country, $provider);
readfile($filename);
//unlink("'".$filename."'");
} else {
echo "ERR_USERNAME_PASSWORD";
exit();
}
我已经从FAQ&也试过,但它只在浏览器上打开,而不是下载。
我也使用了单引号的标题。
我也尝试过 header(Content-Type:text / csv);
另外:
I had already read all questions of this type from FAQ & also tried but it gets open on browser only,instead of downloading.
I had also used header with single quotes.
I also tried header("Content-Type: text/csv");
Also:
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"".$filename."\";" );
header("Content-Transfer-Encoding: binary");
推荐答案
输入您的CSV文件URL,它将显示在浏览器中代替强力浏览器下载。您可以在网站的iframe中打开它。
PUT your CSV file URL, it will display in browser in place of force browser to download. You can open it in iframe in your site.
http://docs.google.com/viewer?embedded=true&url=www.yoursite.com/filename.csv
这篇关于在php而不是下载csv文件,它在浏览器中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!