Looking at Force Download of Files with PHP and Force download file with PHP giving empty file and the one that brought me closest, How to force download an image without a script, but with $_GET?
I'm still unable to come up with a solution to my problem.
I have a html file that allows a user to submit a file to post a file to my 'upload_file.php' PHP script.
<html>
<body>
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
upload_file.php takes in the file, does a bunch of changes to it, pulls data out, and generates an xlsx file in the end via PHPExcel. It's a simple format conversion with a little bit of logic. Currently, for testing, I just had the file written alongside the php file. I could have the upload.php file output a link to said file and call it good.
However, I'd rather the user click the initial upload button and after a few seconds of crunching, the generated file starts downloading to their system. The above links seem to talk about csv or html files being downloaded -- vs an actual file.
Just 'echoing' the filename doesn't seem to do it (as has been suggested in those other threads). I also see a suggestion to just 'set the headers' correctly, which I found the content type should be "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" for an xlsx file -- but no one really fleshes out fully what 'set the headers' means nor how to do it.
I can't imagine it's very hard, but I can't seem to sort it. Can anyone help this beginner?
Also, if possible, I'd love it if the file never existed on the server at all -- but I'm not sure if that's possible with PHPExcel objects...