My thought was to use tmpfile to not worry about cronjobs or running out of disk space, but I can't seem to make the magic happen. Here's my attempt, which is a converted example from the PHP docs of readfile :. I feel like the Content-Disposition and Content-Transfer-Encoding headers are wrong, but I'm not sure how to fix them.
Is there a way to do what I'm attempting here? Note that tmpfile returns a file handle, but all the functions you have need a file path i. So none of those function calls will work correctly. Also basename won't return a file extension either.
Just call it whatever you want, i. As Joshua Burns also says, make sure you're passing in an array to fputcsv or use the assoc parameter. One problem is that tmpfile returns a file handle, while filesize takes a filename as parameter. The following line:. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How to download a temporary file Ask Question.
Asked 8 years, 8 months ago. Active 8 years, 8 months ago. Deleting a file after user download it Ask Question. Asked 11 years, 7 months ago. Active today. Viewed 58k times. Improve this question. Maik Lowrey 2, 1 1 gold badge 5 5 silver badges 21 21 bronze badges. Utku Dalmaz Utku Dalmaz 8, 27 27 gold badges 84 84 silver badges bronze badges.
Add a comment. Active Oldest Votes. Improve this answer. Your best bet would be to not serve the file up directly from the disk and, instead, use a unique URL that you can disable after the download request. Ahmet vardar: Why not just echo out the content of the Zip? Billy: cuz if i do that, there will no download navigation for user — Utku Dalmaz.
Accelerators unhappy. Bill happy :D — Billy ONeal. Show 2 more comments. Lars van den Bosch Lars van den Bosch 5 5 silver badges 7 7 bronze badges.
Perfect for my situation where the file needed to exist while the function ran, but once the script was entirely done, it successfully deleted the temp file. I think its better to setup a Cron job to delete file after some time, say 5 minutes after the download was initiated for the file.
Suit Boy Apps 3, 10 10 gold badges 42 42 silver badges 59 59 bronze badges. Just output the content with the appropriate content type. Add content-disposition if you wish to trigger a download prompt. Improve this answer. Quentin Quentin k gold badges silver badges bronze badges. Use below code to generate files on fly.. Dhiral Pandya Dhiral Pandya 9, 4 4 gold badges 45 45 silver badges 47 47 bronze badges. Community Bot 1 1 1 silver badge. This is the same as this other answer stackoverflow.
I encountered the same problem as eichertc did. Adding the "php" suffix to the opening tag resolves the issue. I checked my apache logs and this was the problem and this post was very useful: stackoverflow. I came here to delete my question because it was resolved but saw it was already deleted. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Who owns this outage?
0コメント