Download File Using Javascript/jQuery

前端 未结 28 2920
悲&欢浪女
悲&欢浪女 2020-11-21 05:11

I have a very similar requirement specified here.

I need to have the user\'s browser start a download manually when $(\'a#someID\').click();

But

28条回答
  •  难免孤独
    2020-11-21 05:37

    Using anchor tag and PHP it can be done, Check this answer

    JQuery Ajax call for PDF file download

    HTML
        Download pdf here
    
    PHP
    
    

    I am checking for file size because if you load pdf from CDN cloudfront, you won`t get the size of document which forces the document to download in 0kb, To avoid this i am checking with this condition

     if($fsize) {//checking if file size exist
          header("Content-length: $fsize");
        }
    

提交回复
热议问题