Server action: Adding php readfile

Hi,

I am building a GET server action download.php that should do the following:

  1. Restrict access to loggedin users
  2. Check the attachments table to see if the $GET.attachment_ID is owned by the loggedin user ({{siteSecurity.identity}}
  3. Retrieve the file path from the attachments table
  4. Output the corresponding file using the readfile php function

While it is straightforward to do steps 1, 2 and 3 using Wappler, I am not able to do step 4.

I tried following: Secure File Download from a path outside of website root but their case is different as they use $POST and have their files outside of the website root (mines are inside)

Can you please advise on the most straightforward way to do readfile in Wappler?

Hi @patrick, any update on this please? Thanks!

We are adding a download action step that should work for your use-case. The limitation for the download step is that it doesn’t allow to pick files outside the website root, but it integrates very nice with all the other server connect actions and you can use expressions to generate the file path and give a different filename for download. It should probably be available in tomorrows Wappler update.

1 Like

that’s lovely, thanks loads

Here is the resulting guide, thanks again: File Downloads with Server Connect

1 Like