PHP detect when the file is done downloading






















Look this answer on how to Detect when browser receives file download I'm pretty sure you can have a good result like this. I hope this help others, Mike. Community Bot 1 1 1 silver badge. Francois Francois 27 3 3 bronze badges. This does not work. It returns without error, assuming the file is small enough to fit in the output buffer in one go, and then the code proceeds to the database update. Nothing is propagated upwards from the TCP layer to indicate delivery to the other side of the pipe.

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. Podcast what if you could invest in your favorite developer? Who owns this outage? Or we might scan the last few characters of the file name and reject files ending with a certain extension.

Unfortunately, these methods are hardly sufficient, as one can easily change the extension of a file to bypass this restriction. Hence MIME types can be pretty easily spoofed too. Magic bytes are essentially signatures that vary in length between 2 to 40 bytes in the file headers, or at the end of a file. How about using an Ajax control to initiate -and maintain- the download, and, on completion verifying its integrity and running an update to your db?

I'd suggest not automatically assuming your customers are going to rip you off, though, whatever you end up choosing. Asking them nicely 'did it work for you? But, regardless, while some of your users might say 'no' just for the extra copy you have to balance the cost of that against the cost of your increased workload to prevent its happening. I don't think it's possible via php to know how many bites have been sent out and actually downloaded via the client , since there's no way to know if the user has cancelled the download or received the entire file.

There is a solution if you are mixing php for server side call an javascript for client complete call. Look this answer on how to Detect when browser receives file download. The following code works. If the download is stopped by the client, the database is not updated and the link can fire again.

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. Asked 12 years, 1 month ago. Active 3 years, 7 months ago. Find centralized, trusted content and collaborate around the technologies you use most. Connect and share knowledge within a single location that is structured and easy to search.

I don't even need to show the progress in real time, I am only interested in the very specific event: "when the download completes". Based on my research, it seems like it would have to be determined from the serverside as there is no ondownloadready event and I don't think it is possible to intercept browser events.

How would I go about checking the bytes sent from the server for a PHP forced download? For the project I am working on, it is required that after the download starts, the page redirects to or displays a "please wait while the download completes" page. Then, once it is complete, it should redirect to or display a "Your download is complete, thank you" page. I am open to other ideas that would achieve the same result. I have a large install file an exe on my web server that people download and install from.

Looking at my log files, I see a lot of people downloading it, but no way to tell for sure if they completed the download or cancelled out before it completed. Is there any function in PHP that would allow the web server to send the file and detect a completion or cancellation? Any help would be greatly appreciated. Thanks, Dan. Follow Post Reply. You could check the byte count in the web server log to see if the whole file was transferred. Thank you very much.



0コメント

  • 1000 / 1000