1

zend frame works を使用しています。アプリケーションにファイル ダウンロード セクションを含めたい。私はこのコードを使用しています

> header('Content-Type: application/doc'); header('Pragma: no-cache');
> header('Content-Disposition: attachment; filename="'.$resume.'"');
> readfile(RESUME_PATH_WS . $resume);

しかし、このコードは機能していません。0byte のファイルを返します。zend フレームワークでファイルをダウンロードする方法を教えてください

4

1 に答える 1

1
     public function downloadAction() {

           $this->_helper->layout->disableLayout();
            $this->_helper->viewRenderer->setNoRender();

            $filename = $this->_request->getParam('filename');

            $filePath = folder/path to file/ . $filename;

            if (file_exists($filePath)) {
                $fileName = basename($filePath);
                $fileSize = filesize($filePath);


                header("Cache-Control: private");
                header("Content-Type: application/stream");
                header("Content-Length: " . $fileSize);
                header("Content-Disposition: attachment; filename=" . $fileName);


                readfile($filePath);
                exit();
            } else {
                die('The provided file path is not valid.');
            }
        }

単にあなたのhtml側で

<a href="path to your controller/downloadaction/filename/<name of file you want to download>">Download</a>
于 2012-05-16T06:15:01.263 に答える