dongmi5177 2017-08-08 13:29
浏览 397

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

Scenario: I've a link to download a pdf file. Upon clicking it, an ajax call runs and returns the file to download. (Ajax implemented to hide the file path for security reasons)

Problem: The code is working perfect with http/non-ssl path. But when site is moved to https the same code is not working.

Question: Is there any thing which i am missing for SSL/HTTPS into the code? This code is written in to 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);


    } 
  • 写回答

1条回答 默认 最新

  • dongtan5558 2018-08-30 20:41
    关注

    I believe ...I am maybe wrong ... You are maybe not changed all urls inside WordPress properly.

    If you did, according to https://codex.wordpress.org/Function_Reference/admin_url

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

    use second parameter to force https

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据