脚本宝典收集整理的这篇文章主要介绍了Cakephp 2.3.x发送文件并强制下载mp4文件,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我想强制每http://book.cakephp.org/2.0/en/controllers/request-response.html#cake-response-file下载一个mp4文件
在我的“视图”中,我有以下代码正确搜索文件名,找到文件名,并显示下载链接:
<?PHP $filename = APP . 'webroot/files/' . $dance['Dance']['id'] . '.mp4'; if (file_exists($filename)) { echo $this->HtML->link('DOWNLOAD',array('controller' => 'dances','action' => 'sendfile',$dance['Dance']['id'])); } else { echo 'Coming soon: available APRil 16th'; } ?>
当用户点击链接时我想强制下载mp4文件.在我的控制器中,我有以下代码不起作用:
public function senDFile($id) { $file = $this->Attachment->getFile($id); //Note: I do not understand the 'Attachment' and the 'getFile($id)' $this->response->file($file['webroot/files/'],array('download' => true,'name' => 'Dance')); //Return reponse object to prevent controller From trying to render a view return $this->response; }
我不明白’附件’和’getFile()’
$this->response->file(WWW_ROOT.'files/'. $id .'.mp4','name' => 'Dance'));
您可以删除$this-> Attachment-> getFile行,因为它与您的情况无关.
如果有帮助,请告诉我!
以上是脚本宝典为你收集整理的Cakephp 2.3.x发送文件并强制下载mp4文件全部内容,希望文章能够帮你解决Cakephp 2.3.x发送文件并强制下载mp4文件所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。