How to make a link to download attachments for webmail using IMAP and PHP?

I'm working on a mobile mail project, and now I'm looking for a way to create a link (or list of links) so that email users can download attachments in messages. It will look like this: <a href="???">title of the file.ext</a>

I can already receive the attachments and display it as a terrible wall of special characters, but I cannot find a way to create a link to download the attachment after the contents of the email are displayed.

Does anyone have any suggestions?

+3
source share
1 answer

Give the client a forced download to the client.

header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=\"file.zip\"");
header("Content-Length: ".filesize("file.zip"));

The length of the content is optional.

You will need to create a php script that will be associated with this:

<a href="http://server/script.php?emailId=12345&fileName=file.zip">

And the PHP script will just send the headers above and print the full contents of the file.

+2
source

Source: https://habr.com/ru/post/1787465/


All Articles