I have 3 pages - the origin page with a button, the destination page, and the download page which saves a file using content-disposition
- in which I need to serve the destination page after a file downloads from a button press on the origin page.
The flow of redirects should be something like:
origin page -> [button click] -> download file -> redirect to destination page
I want the user to be able to download the file and be redirected with only one press of the button. I have tried doing this in the following way, but it was to no avail:
To process the download of the image, I use the following code on the download file
<?php
header('Content-disposition: attachment; filename=calendar.jpg');
header('Content-type: image/jpeg ');
readfile($_POST['_img_src']);
?>
When the button is pressed, it directs the user to the download page and the image downloads, however it does not redirect to the destination page. After adding header('Location: /directory/mypage.php');
it nullifies the download and only redirects to the destination page due to the header conflict.
If I put the image download code at the beginning of the destination file, the download is corrupted and the content does not load.
Any help is greatly appreciated!
EDIT: The image to download was already created by the user and stored on the server. The origin page sends the image's link (by post method) to the download file, so I can not go to the destination page and then redirect to the download file as explained on here. It could be possible if there is a way to send data by post method while redirecting to the download file automatically. But I think it will make more complex the problem.