Pdf file download code not working with SSL / HTTPS?

Script: I have a link to download a PDF file. After clicking on it, an ajax call is made and returns a file to upload. (Ajax implemented to hide the file path for security reasons)

Problem: The code works fine with http / non-ssl path . But when the site navigates to https, the same code doesn't work.

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


    } 

      

+3


source to share





All Articles