我想使用添加下载链接按钮
<a href="<?php download_paper($id) ?>">Download</a>
在互联网上搜索后,我得到了代码:
$file_obj = new FileData($_REQUEST['id']);
// Added this check to keep unauthorized users from downloading - Thanks to Chad Bloomquist
checkUserPermission($_REQUEST['id'], $file_obj->READ_RIGHT, $file_obj);
$realname = $file_obj->getName();
if (isset($revision_id)) {
$filename = $revision_dir . $request_id . ".dat";
} elseif ($file_obj->isArchived()) {
$filename = $GLOBALS['CONFIG']['archiveDir'] . $_REQUEST['id'] . ".dat";
} else {
$filename = $GLOBALS['CONFIG']['dataDir'] . $_REQUEST['id'] . ".dat";
}
if (file_exists($filename)) {
// send headers to browser to initiate file download
header('Cache-control: private');
header('Content-Type: '.$_GET['mimetype']);
header('Content-Disposition: attachment; filename="' . $realname . '"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
readfile($filename);
} else {
echo msg('message_file_does_not_exist');
}
此处$revision_dir=$GLOBALS['CONFIG']['revisionDir'].'/'$_请求['id'].'/';
但我想从sitename.com/pdm-uploads/下载文件
保留上面的代码,只需在<a>
标记中添加下载即可。
<a href="<?php echo home_url( '/' ).'path/'. $download->realname ?>" download>Download Now</>