PHP File Download

Source: Internet
Author: User

* Download File
*
* @param string $downloadFile
* @param string $downloadName
*/
Private Function DownLoad ($downloadFile, $downloadName) {
Header ("Cache-control:public");
Header ("Content-description:file Transfer");
Header (' content-disposition:attachment; Filename= '. $downloadName); Filename
Header ("Content-type:application/zip"); In the ZIP format
Header ("Content-transfer-encoding:binary"); Tell the browser that this is a binary file
Header (' Content-length: '. FileSize ($downloadFile)); Tell the browser, file size
@readfile ($downloadFile);
}
------------------------------------------------------------------------------------

/**
* Customer Credit Application Attachment download
*/
Public Function attachmentdownloadaction () {
$request = $this->getrequest ();

$filePath = $request->getparam (' FilePath ');
$filePath = zend_filter::filterstatic ($filePath, ' Stringtrim ');
$filePath = zend_filter::filterstatic ($filePath, ' striptags ');
$filePath = Application_path. " /.. /public ". $filePath;

$fileName = $request->getparam (' fileName ');
$fileName = zend_filter::filterstatic ($fileName, ' Stringtrim ');
$fileName = zend_filter::filterstatic ($fileName, ' striptags ');
$fileName = Iconv ("UTF-8", "GB2312", $fileName);

if (file_exists ($filePath)) {
$this->attachmentdownload ($filePath, $fileName);
} else {
throw new Member_model_notexist_exception (' attachment does not exist! ‘);
}
}
Private Function Attachmentdownload ($filePath, $fileName)
{
$file = file_get_contents ($filePath);
$this->getresponse ()
->setbody ($file)
->setheader (' Content-type ', ' Application/octet-stream ')
->setheader (' Content-disposition ',
' Attachment; Filename= "'. $fileName. ')
->setheader (' Content-length ', strlen ($file));

$this->_helper->layout->disablelayout ();
$this->_helper->viewrenderer->setnorender (TRUE);

Header (' set-cookie:filedownload=true; path=/');
$this->getresponse ()->sendresponse ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.