我想在网站上添加下载文件,但是当我点击下载它显示奇怪的角色。我不知道错误是什么。我在我的代码中添加了类型application / octet-stream。我认为存在许可问题,但我也在c-panel中设置了许可:
这是我的文件下载代码:
if(isset($_REQUEST["file"])){
$file = urldecode($_REQUEST["file"]);
$filepath = ABSPATH.'/wp-content/themes/xorisk/document_upload/'.$file;
if(file_exists($filepath)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($filepath).'"');
header("Content-Type: mime/type");
header('Expires: 0');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Cache-Control: must-revalidate');
header('Pragma: public');
header("Content-Transfer-Encoding: binary");
header('Content-Length: ' . filesize($filepath));
readfile($filepath);
exit;