Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 包括带有内容处置头的PHP脚本以强制下载_Javascript_Php_Ajax_Include_Content Disposition - Fatal编程技术网

Javascript 包括带有内容处置头的PHP脚本以强制下载

Javascript 包括带有内容处置头的PHP脚本以强制下载,javascript,php,ajax,include,content-disposition,Javascript,Php,Ajax,Include,Content Disposition,“class.generateDownload.php”中的脚本生成一个包含添加文本的图像,并立即将其下载到我的机器上 它接受“日期”的POST数据,以获取发布日期的图像/文本 $date = $_POST['day']; //UTF-8 header('Content-type: text/html; charset=utf-8'); //Includes include 'gdtext/Color.php'; include 'gdtext/Box.php'; include 'cla

“class.generateDownload.php”中的脚本生成一个包含添加文本的图像,并立即将其下载到我的机器上

它接受“日期”的POST数据,以获取发布日期的图像/文本

$date = $_POST['day'];

//UTF-8
header('Content-type: text/html; charset=utf-8');

//Includes
include 'gdtext/Color.php';
include 'gdtext/Box.php';

include 'class.getSlogan.php';
include 'class.getImage.php';

use GDText\Box;
use GDText\Color;


        $slogan_txt = dailySlogan($date);
        $img = dailyImage($date);


        //Set Imagepath
    $imgPath = '../../images/output/' . $img['imageName'];


//Create Image
$im = imagecreatefromjpeg($imgPath);

//Get X/Y for Box
$image_width = imagesx($im);
$image_height  = imagesy($im);
$y = ($image_height / 2 );
$max_x = ($image_width / 2 );
$start = ($max_x / 2);


//Generate Text
$box = new Box($im);
$box->setFontFace('./RobotoCondensed-Bold.ttf');
$box->setFontSize(110);
$box->setFontColor(new Color(255, 255, 255));
$box->setTextShadow(new Color(0, 0, 0, 50), 0, -2);
$box->setBox($start, $y, $max_x, 0);
$box->setTextAlign('center', 'center');
$box->draw($slogan_txt['en']);


//Debug
//header("Content-type: image/png");
//imagejpeg($im, '../../images/download/motivation_' . $date . '.jpg');

header("Content-Disposition: attachment; filename=\"motivation_" . $date . ".jpg\";");
header('Content-Type: image/jpeg');
imagejpeg($im);
到目前为止,这一切都很完美

不,我需要从另一个页面(index.php)通过按钮调用脚本,单击AJAX帖子:

  <script>
  var php_date = "<?php echo $dateVar; ?>";
  $('.btn').click(function() { 

$.post("lib/web/class.generateDownload.php", {
    date : php_date
    }, function(data) {

    console.log(data);
});

});
</script>

var php_date=“”;
$('.btn')。单击(函数(){
$.post(“lib/web/class.generateDownload.php”{
日期:php_date
},函数(数据){
控制台日志(数据);
});
});
脚本包括在内,但我只是得到脚本的纯文本,没有图像,没有下载。
POST数据正常。

尝试删除第一个
标题('Content-type:text/html;charset=utf-8')