0

php

<a href="<?php echo $path_data['wall_path'];?>">
<?php echo $dimensions_data['width'] . "x" . $dimensions_data['height']; ?></a>

which outputs

<li><a href="wallpapers/2014/04/scape-640x960-640x960.jpg">640x960</a></li>
<li><a href="wallpapers/2014/04/scape-640x1136-640x1136.jpg">640x1136</a></li>
<li><a href="wallpapers/2014/04/scape-720x1280-720x1280.jpg">720x1280</a></li>
<li><a href="wallpapers/2014/04/scape-768x1280-768x1280.jpg">768x1280</a></li>
<li><a href="wallpapers/2014/04/scape-1080x1920-1080x1920.jpg">1080x1920</a></li>

Now what I need to do is when the user clicks any one of the sizes, I want to prompt a save file dialog box containing the appropriate size file. I've read Forcing to download a file using PHP and PHP Force File Download, but based on my understanding, these are for single file downloads. Please correct me if not.

Restrictions: don't want to forward to another page like download.php file when user clicks a link.

Community
  • 1
  • 1
vephelp
  • 552
  • 2
  • 10
  • 24

1 Answers1

1

Normally a browser would not show a download dialog for an image, it will display the image instead, what is the desired behaviour. You can then click "Save As ..." and save the image.

What the browser does with a files depends on the mime type which the web server sends for that file. For jpg images it would be

image/jpeg

If you really want to trick the browser to show a save dialog you need to send a different mime type for that files, like:

application/octet-stream

This can be done using a download.php file (or whatever) which modifies the header and outputs the file. The existence of such a download.php can be hided from the user using rewritten urls.

If you don't want that, you need to tell the web server that it should send a different mime type for that files. If you run apache for example, you can add the following line to your .htaccess file:

AddType application/octet-stream .jpg
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • I'm currently working on local, and using xampp. Sorry, but I haven't tried editing `.htaccess` file. How will I be able to do that? thanks! – vephelp Apr 12 '14 at 15:39
  • I mean what should be the location of the file. I've checked `LoadModule rewrite_module modules/mod_rewrite.so` and `AllowOverride All` settings, then created `.htaccess` file in my `htdocs` folder but it doesn't seem to work. – vephelp Apr 12 '14 at 15:53
  • It is not related to mod rewrite. `AllowOverride FileInfo` would be sufficient in this case, but `All` will work too. I would place the .htaccess in the wallpapers folder. Have you restarted the web server? – hek2mgl Apr 12 '14 at 15:55
  • Also empty your browser cache – hek2mgl Apr 12 '14 at 15:59