有一个问题,我无法提供PHP中的文件以在VUEjs中下载 php代码是
$path= 'somepath';
$loadfile = $_GET['loadmyfile'];
if(file_exists($path.$loadfile)){
if (ob_get_level()) {
ob_end_clean();
}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($path.$loadfile));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($path.$loadfile));
readfile($path.$loadfile);
exit;
}else{
echo 'Cant load a file: '.$_GET['loadmyfile'];
}
但是vue-router是重新加载页面而不下载文件
根据生成<a href='?loadmyfile='+filename>Some document</>
列出了所有需要的vue-router
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule> //space is normal!!
我认为问题是htaccess文件,但我不知道如何正确
请帮助!