2

次のようにphpで動的にファイルを生成しています:

$attachment_url = "http://www.mysite.com/file.jpg";
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="'.basename( $attachment_url ).'"');
header('Content-Transfer-Encoding: binary');
header('Connection: close');
readfile( $attachment_url );

このデータは、jQuery.ajaxを介して渡されます

成功時にファイルダウンロードダイアログを開くようにしたいと思います。

今私はこれを持っています:

success: function(data, textStatus, XMLHttpRequest) {
    var win = window.open();
    win.document.write(data);
}

これにより、新しいウィンドウが開き、未加工のファイル データが表示されます。代わりに、ダウンロード ダイアログを開きたいと思います。

4

1 に答える 1