我正在制作一个文件,用于下载存储在我的网站中的文件。但是,当我尝试单击按钮下载文件时,它不会加载文件。我正在使用header函数来做这件事。有人能回答我为什么在使用wp-load.php
还是我做错了什么。这是我的代码:
<?php
require_once(dirname(__FILE__) . \'/wp-load.php\');
function lastlink($str){
$regexp = "<a\\s[^>]*href=(\\"??)([^\\" >]*?)\\\\1[^>]*>(.*)<\\/a>";
if(preg_match_all("/$regexp/siU", $str, $matches)) {
$str= end($matches[2]);
}
return $str;
}
$url=$_POST[\'url\'];
$id=url_to_postid($url);
$content_post = get_post($id);
$content = $content_post->post_content;
$content = apply_filters(\'the_content\', $content);
$content = str_replace(\']]>\', \']]>\', $content);
$ur=loadd(lastlink($content));
$name = \'gameofthrones.mp4\';
if(isset($_POST["downloadfile"])) {
$url=str_replace(" ","%20",$ur);
header(\'Expires: 0\'); // no cache
header(\'Cache-Control: must-revalidate, post-check=0, pre-check=0\');
header(\'Last-Modified: \' . gmdate(\'D, d M Y H:i:s\', time()) . \' GMT\');
header(\'Cache-Control: private\', false);
header(\'Content-Type: application/force-download\');
header(\'Content-Disposition: attachment; filename="\' . $name . \'"\');
header(\'Content-Transfer-Encoding: binary\');
header(\'Content-Length: \' . get_remote_size($url)); // provide file size
header(\'Connection: close\');
readfile($url);
}
?>
<form method="POST">
<input type="submit" value="DOWNLOAD FILE" name="downloadfile"/>
</form>
看一看,纠正我。