0

In an effort to serve excellent image files to only legit guests of my site, I needed to make PHP code. I narrowed the problem down to a few lines of code as follows:

The first piece is a simple web form with one button that takes a user to another section of the site (the actual image) via the POST method (so hackers have a harder time requesting the images). Anyways heres that code:

<form method="post" action="dltestb.php">
  <div>
    <input class="a b" type="submit" value="DL">
  </div>
</form>

The following PHP file is the dltestb.php file in the same folder as the form.

When the user selects the button, the download should start or the user should be asked to download the image. This works with my old opera browser and firefox 45 browser on my computer. It also works on chrome 35 for my tablet, however some of my website guests on mobile are unable to download images and code execution is the same (with the exception of the output filename). I also could not use it with the default browser on my tablet.

Is there something in these new browsers that I need to be aware of that is preventing my script from successfully working?

  • What does your script do? What response is your script sending? What actually happens in the browsers where this is not working? – MrWhite Aug 29 '18 at 12:20
  • There's no javascript. But all the PHP script does is loads an internal file and dumps it out as the body and uses the HTTP headers to define the output as the image file. On the stock android browser, nothing happens. On other mobile browsers, I'm uncertain because the person managing the server told me that people from various mobile devices with newer web browsers had a hard time downloading the pictures on mobile. – Mike Aug 29 '18 at 15:37
  • Are you saying that it's just "mobile" browsers that have problems downloading? Mobile browsers typically need "storage access" to be able to download files. Has this previously been "denied"? Also, browsers typically download to just one location (the user has no choice) and this is often performed in the background. It may not be obvious that the file has downloaded and the user must switch out of the browser/application to view it. "stock android browser" - how old are these devices? The default Android browser recent mobiles is "Google Chrome". – MrWhite Aug 29 '18 at 16:09
  • It may be easier and more user-friendly to simply "open" the image in a mobile browser, rather than "force downloading". The user then has control to "download" (ie. save) it, share it, etc. – MrWhite Aug 29 '18 at 16:14
  • True but I'm trying to make it so that random content scrapers don't download the images endlessly without permission. – Mike Aug 29 '18 at 16:31

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.