fivestringsurf Posted March 8, 2015 Share Posted March 8, 2015 (edited) I have a php application that serves pdf downloads. It works fine on all devices and browsers with one small but really annoying side-effect (edge-case for sure) When I look at my download logs anytime the download is triggered from Chrome on Android it is called twice! Bizarre behavior and I can't figure it out. Some background: The download is a pdf that get's created on the fly. All requests get processed through my index.php controller. I was serving the request with javascript via: window.open('export?file=something_to_inform_the_controller'); Works great in all browsers and devices but android chrome triggers this twice. So I got wise and though maybe a direct link would work better: <a target="_blank" href="http://mysite.com/export?file=abc123" download="file.pdf">DL link</a> or <a target="_blank" href="http://mysite.com/export?file=abc123">DL link</a> or <a target="_self" href="http://mysite.com/export?file=abc123" download="file.pdf">DL link</a> or <a target="_self" href="http://mysite.com/export?file=abc123">DL link</a> Nope, none of these flavors prevents android/chrome from double downloading. Then I researched my php header settings and tried: content-disposition: inline vs. content-disposition: attachment with no success Note, the download is logged when the controller processes the request for the download. I have duplicated download events for all downloads on android/chrome. It's strange that I have not found a solution online for this or maybe I'm overlooking something silly. Any ideas? Edited March 8, 2015 by fivestringsurf Quote Link to comment https://forums.phpfreaks.com/topic/295172-dowload-links-get-called-2x-via-androidchrom/ Share on other sites More sharing options...
Solution kicken Posted March 8, 2015 Solution Share Posted March 8, 2015 (edited) It's because the browser initially requests the URL. Once it determines that it's content it can't handle and needs to be downloaded it passes the URL off to a separate download manager application which will then re-request the url and complete the download in the background. This behavior is by design, there isn't anything you can do to make it issue only a single request. Edited March 8, 2015 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/295172-dowload-links-get-called-2x-via-androidchrom/#findComment-1507887 Share on other sites More sharing options...
fivestringsurf Posted March 8, 2015 Author Share Posted March 8, 2015 (edited) @kicken, excellent answer. The reason I was most annoyed by this was when a user looks at their download history if they have been using an android device everything is doubled! I guest the solution is: a) screw you android users (you're log activity is doubled for download requests) b) don't log requests made by same user/link within <3 seconds of one another Thanks again for your answer. Edited March 8, 2015 by fivestringsurf Quote Link to comment https://forums.phpfreaks.com/topic/295172-dowload-links-get-called-2x-via-androidchrom/#findComment-1507890 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.