I tried
$file = file_get_contents("http://my_site/wp-content/uploads/2013/04/Dev-TipsTricks.pdf", true);
echo $file;
but browser showing special characters (see image).
and I also tried
$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;
it downloads file when I run from localhost but on live server it is also showing special characters see image.
I also followed it file_get_contents
I also tried for 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");
This is happening with all file extensions.
File path are correct & if I echo path & copy/paste in new browser tab it opens pdf & if path for docx browser allows to download.
browser following warning shows:
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
and this is the code in 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
}
now i can't able to figure out where is the bug......?