PDF 파일을 다운로드하려고하는데 다운로드 버튼을 클릭하면 파일이 확장되지 않고 다운로드됩니다. 즉, 파일을 다운로드 할 때 PDF 확장이 없습니다!파일을 확장명없이 다운로드하고 있습니까?
액션 :
public function executeDownload(sfWebRequest $request) {
$this->ebook_id = $request->getParameter('ebook', $this->default_ebook);
$this->ebook = $this->ebooks[$this->ebook_id];
if (!is_array($this->ebook))
return;
// Allow user to download the ebook (and make sure there is no other output)
$this->setLayout(false);
sfConfig::set('sf_web_debug', false);
$content = sfConfig::get('sf_root_dir').'/web'.$this->ebook['ebook'];
//echo "<p>PDF: $content</p>"; var_export(filesize($content));exit;
// Check if the file exists
$this->forward404Unless(file_exists($content));
// Record the download for this eBook
$c = new Criteria();
$c->add(EbookDownloadsPeer::EBOOK_SLUG, $this->ebook_id);
$ebook = EbookDownloadsPeer::doSelectOne($c);
$ebook->setLastDownloaded(time());
$ebook->setEbookDownloads($ebook->getEbookDownloads()+1);
$ebook->save();
// Adding the file to the Response object
$content_type = (in_array($this->ebook_id, array('readyourbody', 'whyamifatigued', 'nutrientsfromfood'))) ? 'application/pdf': 'image/jpeg';
$this->getResponse()->clearHttpHeaders();
$this->getResponse()->setHttpHeader('Pragma: public', true);
$this->getResponse()->setContentType($content_type);
$this->getResponse()->setHttpHeader('Content-Disposition', 'attachment; filename="'.$this->ebook['name'].'"');
$this->getResponse()->setHttpHeader('Content-Length', filesize($content));
$this->getResponse()->sendHttpHeaders();
$this->getResponse()->setContent(readfile($content));
return sfView::NONE;
}
템플릿 :
<div class="cyan3 txt-large txt-c">
<?php echo link_to('Click here','ebooks/download?ebook='.$ebook_id,'') ?> to <?php echo link_to('download it now','ebooks/download?ebook='.$ebook_id,'') ?>!
</div><br />
</div>
합니까'$ this-> 전자 책 [ '이름'] 같은 것이'확장자를 가진 파일 이름을 포함 그것 때문에 라인
$this->getResponse()->setHttpHeader('Content-Disposition', 'attachment; filename="'.$this->ebook['name'] . '"');
이 값을 추가 하시겠습니까? 어쩌면 확장 기능이 전자 북 배열의 다른 필드에있을 수도 있습니다. –
아니요, @MarkC라는 이름 일뿐입니다. –
.pdf로 전자 북명을 입력하십시오. – rahulsm