$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>download link for uploaded images for wordpress|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

download link for uploaded images for wordpress

matteradmin11PV0评论

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

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far