download link for uploaded images for wordpress

admin2025-06-02  1

Is there a way have a download link so that users can directly download uploaded images on a wordpress theme?

I have seen this guide for something like this / but it is not wordpress specific and was not able to get it to work

Is there something easier to implement?

Currently i am able to link directly to the image and users are able to view the image in the browser but i want users to be able to download instead.

thanks

Is there a way have a download link so that users can directly download uploaded images on a wordpress theme?

I have seen this guide for something like this http://fcontheweb/articles/force_download/ but it is not wordpress specific and was not able to get it to work

Is there something easier to implement?

Currently i am able to link directly to the image and users are able to view the image in the browser but i want users to be able to download instead.

thanks

Share Improve this question edited Mar 12, 2019 at 14:53 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Mar 12, 2019 at 7:15 uberrebuuberrebu 1032 bronze badges 3
  • Yes, that is what you'll have to do: set a Content-Disposition: attachment header, which means create a new endpoint to make the request to which will add the header and stream the file, like your example code. I haven't done this for WordPress but at first glance it looks like you could use admin_ajax or maybe the REST API – Rup Commented Mar 12, 2019 at 10:32
  • hmm dont know how to do that? is it too complicated to do as an answer i can follow? – uberrebu Commented Mar 12, 2019 at 14:45
  • I haven't tried it either, sorry. I don't know anything more than the pages I linked to. – Rup Commented Mar 12, 2019 at 14:57
Add a comment  | 

1 Answer 1

Reset to default 1

You should just be able to use the HTML5 download attribute for that. So just make your links look like this:

<a href="<?php echo wp_get_attachment_image_url($id); ?>" download>Download Image</a>

where $id is the attachment ID

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748814449a313945.html

最新回复(0)