嗨,我使用 MediaView 在 cakePHP 框架中实现了文件下载功能,原因有几个,我通过 URL 传递了一个参数,该参数与文件名一起显示,我需要删除 URL 参数,我试过但失败了,请帮帮我。
我下载文件的代码
$fileExtn = explode('.', $this->contentItem['file_path']);
$url = $this->contentItem['file_path'];
$urlArr = explode('/', $url);
$fileExtn = end($fileExtn);
if(in_array($fileExtn, $this->MEDIAMAP)) {
$fileExtn = str_replace('.', '', $fileExtn);
if(!empty($urlArr)) {
$fileName = end($urlArr);
$fileNameWOExtn = explode('.', $fileName);
//$fileNameWOExtn = $fileName[0];
$fileNameWOExtn = $fileName;
unset($urlArr[count($urlArr)-1]);
$url = implode(DS, $urlArr);
}
$this->view = 'Media';
$params = array(
'id' => $fileName,
'name' => $fileNameWOExtn,
'download' => false,
'extension' => $fileExtn, // must be lower case
'path' => APP . 'views' . DS . 'static'. $url .DS // don't forget terminal 'DS'
);
$this->set($params);
我的网址是这样的:/uploads/leave_policy_leave_policy_tasks_v1.3.xlsx
提前致谢