我试过了
$file = file_get_contents("http://my_site/wp-content/uploads/2013/04/Dev-TipsTricks.pdf", true);
echo $file;
但浏览器显示特殊字符(见图)。
我也试过
$mime_type = getMimeType($extension[1]);
ob_start();
header("Content-type: $mime_type");
header("Content-disposition: attachment; filename=$file");
ob_clean();
flush();
readfile($upload_dir['baseurl'].'/'.$file);
exit;
当我从本地主机运行时它会下载文件,但在实时服务器上它也显示特殊字符,请参见图像。
我也跟着它file_get_contents
我也试过pdf
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file_name");
header("Content-Type: application/pdf");
header("Content-Transfer-Encoding: binary");
所有文件扩展名都会发生这种情况。
文件路径是正确的&如果我在新的浏览器选项卡中回显路径&复制/粘贴它会打开pdf &如果docx浏览器的路径允许下载。
浏览器以下警告显示:
Warning: Cannot modify header information - headers already sent by (output started at /home/me/public_html/my_site/wp-admin/includes/template.php:1638) in /home/me/public_html/my_site/wp-admin/download.php on line 224
这是template.php中的代码
function _wp_admin_html_begin() {
$admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : '';
?>
<!DOCTYPE html>
<!--[if IE 8]>
<html xmlns="http://www.w3.org/1999/xhtml" class="ie8<?php echo $admin_html_class;?>"<?php do_action('admin_xml_ns');?><?php language_attributes();?>>
<![endif]-->
<!--[if !(IE 8) ]><!-->
<html xmlns="http://www.w3.org/1999/xhtml" class="<?php echo $admin_html_class;?>"<?php do_action('admin_xml_ns');?><?php language_attributes(); ?>>
<!--<![endif]-->
<head>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
<?php
}
现在我无法弄清楚错误在哪里......?