用readfile获取垃圾字符

时间:2016-02-10 22:53:34

标签: php readfile downloadfile

我有一个csv文件,只有一行保存在我系统的临时位置  我只想使用php下载文件 当我从临时位置打开但是使用代码

下载文件时,该文件看起来非常好
 $file = 'c:\\wamp\\dev.solarjoy.com\\affiliates\\temp\\ziplist.csv';
         if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
    }
    else
    {
    echo 'file does not exist';
    }

该文件将原始html添加到其中。有什么问题?

1 个答案:

答案 0 :(得分:0)

I figured out the solution, I was putting the fileread code after the head tag, so for some reason readfile was inserting it in the file (should not happen that way though) so I moved the code at top of the page and it fixed it.