pdf文件下载代码无法使用SSL / HTTPS?

问题描述 投票:3回答:1

场景:我有一个下载pdf文件的链接。单击它后,将运行ajax调用并返回要下载的文件。 (出于安全原因,Ajax实现了隐藏文件路径)

问题:代码与http / non-ssl路径完美配合。但是当站点移动到https时,相同的代码不起作用。

问题:代码中是否有SSL / HTTPS遗漏的东西?此代码写入wordpress

 <a  class="red contract-btn" id="contract_link" data-contract="<?php echo base64_encode($cont_file); ?>" href="" >View Contract</a>

 <script>
jQuery("#contract_link").on('click',function(e){  

e.preventDefault();
 var $this=jQuery(this).data('contract'); 
      var ajaxData = {
                'action': 'contract_file_download', 
                'cont_file':$this  
        }

        jQuery.ajax({

            type: "POST",
            url: "<?php echo admin_url('admin-ajax.php'); ?>",
            data: ajaxData, 
            success: function( response ) { },
            error: function() {   
            alert("Error!");
            }

        });
    });

</script>  

PHP:

add_action("wp_ajax_contract_file_download", "contract_file_download");
add_action("wp_ajax_nopriv_contract_file_download", "contract_file_download"); 
function contract_file_download(){
 $File_path=base64_decode($_POST['cont_file']);  
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($File_path) . '"');
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($File_path));

ob_end_flush();   

set_time_limit(0);

readfile($File_path);


    } 
php ajax wordpress pdf ssl
1个回答
0
投票

我相信......我可能错了......你可能没有正确改变WordPress中的所有网址。

如果你这样做,根据https://codex.wordpress.org/Function_Reference/admin_url

admin_url('admin-ajax.php','https');

使用第二个参数强制https

© www.soinside.com 2019 - 2024. All rights reserved.