I have a PHP function that downloads differents files after clicking on a button (if we click on the PDF button If you do this, then this PDF file, if we click the Dock button, it will load a Doctor file). This is the same function for both buttons
My problem occurs when I download a file. If it is a PDF, IE will open another page, and it will close it and give me the option to download the file, but if it is DOC, IE will not close it by opening another page.
The code (for me) is the same, I do not see any difference.
& lt; Pre & gt; & Lt; Code & gt; Public function LettrecadrageAction () {$ nom = $ _POST ['type']; Switch ($ nm): Case 'Feature DOC': $ Path = "DDL / Letter_DecackDrade.Dock"; Header ('content-description: file transfer'); Header ("content-type: application / force-download"); Header ("content-dispute: attachment; filename = letre_dekekdraze.doc"); Header ('content-transfer-encoding: binary'); Header ('expiration: 0'); Header ('Cash-Control: Required-Modified, Post Check = 0, Pre-Check = 0'); Header ('pragma: public'); Header ('content-length:'. File size ($ path)); Ob_clean (); Flush (); Readfile ($ path); break; Case 'Epicerial PDF': $ path = "DDL / Letter_DekraDrade.pdf"; Header ('content-description: file transfer'); Header ('content-type: application / force-download'); Header ("content-dispute: attachment; file name = latre_dekekdrase.pdf"); Header ('content-transfer-encoding: binary'); Header ('expiration: 0'); Header ('Cash-Control: Required-Modified, Post Check = 0, Pre-Check = 0'); Header ('pragma: public'); Header ('content-length:'. File size ($ path)); Ob_clean (); Flush (); Readfile ($ path); break; Endswitch; Go out; } & Lt; / Code & gt; & Lt; / Pre & gt; JS action to click
& lt; Pre & gt; & Lt; Code & gt; $ ('.ldc_dl'). Click (function () {var f = document.createElement ("form"); f.method = "POST"; f.name = "form"; f.target = "_blank"; F.setAttribute ('style' , 'Display: none;'); f.action = "http: //" + document.domain + "/ exploitation / lettrecadrage /"; var fHtml = document.createElement ("input"); FHtml.type = "text "; FHtml.name =" type "; fHtml.value = $ (this) .html (); console.log (fHtml); var fSubmit = document.createElement (" input "); fSubmit. Type =" submit " ; F.appendChild (fHtml); f.appendChild (fSubmit); document.b.appended child (f); f.submit (); document.body.removeChild (f); back true;}) / Code & gt; & Lt; / Pre & gt; HTML code for the button
& lt; Pre & gt; & Lt; Code & gt; & Lt; Div class = "tab-leaf fade" id = "ldc" & gt; & Lt; P & gt; La Letre de Cadrage a unique N button button id = "ldc_dl_doc" class = "btn btn-link ldc_dl" type = "button" & gt; Fichre DOC & lt; / Button & gt; & Lt; / P & gt; & Lt; P & gt; O & n button; Id = "ldc_dl_pdf" class = "btn btn-link ldc_dl" type = "button" & gt; Fichre PDF & lt; / Button & gt; & Lt; / P & gt; & Lt; / Div & gt; & Lt; / Code & gt; & Lt; / Pre & gt; (buttons are 'epicher pdf' and 'feature doc')
editing - solution Jbl help in the comment, I solved my problem using an iframe:
var frame = document.createElement ("iframe"); Frame.setAttribute ("src", "_blank"); and modify my form target
f.target = frame;
Content-transfer-encoding header used in MIME There is no point in sending email messages to it on HTTP. Content-dispute: attachment; Header is asking the browser to save it, rather than open it in the browser. Therefore, instead of content type: application / force-download , I suggest using the appropriate content-type for PDF and DOC files: Content Type: Application / pdf content-type: application / vnd.ms-word
No comments:
Post a Comment