October 24, 2024
Chicago 12, Melborne City, USA
PHP

PHP function to download file when called by a webhook


I have a webhook incoming to my server that runs a php script create an excel spreadsheet and stores it on a folder on my server. What I want to do is trigger a download to the users PC of the file but everything I do either doesn’t work at all or sends the file as code to the http response 200.

Ive got everything to create and store the excel file using PHPSpreadsheet and the file name is stored in

$fileUrl="https://example.co.uk/folder/" . $filename;

Ive tried all suggestions I can find on google but using header and readfile() all point back to the webhook sender not the browser downloads.

Is what Im trying to do even possible

Something like this would normally work but not when called from a webhook, it just sends code to the webhook sender as a response 200. On a side note, I cant change anything on the site that sends the webhook

 header('Content-Description: File Transfer');
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment; filename="' . $filename   
 . '"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($filepath));
    readfile($filepath);   



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video