在Zend 1(PHP)中下载文件:文件名是日语

时间:2016-07-05 07:05:40

标签: zend-framework downloadfile

我使用Zend FW 1下载文件。

文件需要下载的文件名为japanese るファイルを選択.pdf

$this->path:是文件路径。例如:D:\るファイルを選択.pdf

这是我在PHP中的代码

public function send() {
    if($this->checkPath()) {
        // fileinfo extention enable
        $type = mime_content_type($this->path);

        if ($this->getRequest()->isSecure()) { // HTTPS sites - watch out for IE! KB812935 and KB316431.
            header('Content-Description: File Transfer');
            header('Cache-Control: max-age=10');
            header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
            header('Pragma: ');
        } else { //normal http - prevent caching at all cost
            header('Content-Description: File Transfer');
            header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
            header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
            header('Pragma: no-cache');
        }

        if ($this->isIE()) {
            $name = rawurlencode($this->name);
        } else {
            $name = $this->s($this->name);
        }

        $name =  urlencode($name);
        $Disposition = "attachment;filename*=UTF-8''$name";
        $this->getResponse()->setHeader('Content-Type', $type . ";charset=utf-8")
                            ->setHeader('Content-Disposition', $Disposition, true)
                            ->setHeader('Content-Transfer-Encoding', 'binary', true)
                            ->setHeader('X-Sendfile', readfile($this->path), true)
                            ->sendResponse();

        unlink($this->path);
    }
}

mime_content_type($this->path)重新调整:

  

mime_content_type(D:\るファイルを选択.pdf):无法打开流:没有这样的   文件或目录...

我在UTF-8

中设置了getResponse

1 个答案:

答案 0 :(得分:0)

尝试使用finfo

$result = new finfo();
echo $result->file($filename, FILEINFO_MIME_TYPE);