Check if file is downloaded php






















It will tell you when you have finished sending bytes to the user, but it says nothing about how many of them the user has actually received. In reality, there is no way with PHP which is a server-side, not a client-side, language to truly detect when a file download has completed. The best you can do is log the download in your database when it begins. If you absolutely, completely and totally need to know when the download has completed, you'll have to do something like embed a Java applet or use Flash.

However, usually that is not the correct answer in terms of usability for your user why require them to have Java or Flash installed just to download something from you? As Marc W's already pointed out php can only tell you what you've sent from the server, not what the client's received, so using strictly php is a non-starter. But there is always the possibility of asking the user to confirm the download by pressing a button that calls a JS check by generating an MD5 hash and comparing that to the MD5 hash of the file on your server the on-server MD5 being generated by you , and on a successful comparison use that JS script to update your db or use it to call a php-script to do the same.

You could always just ask them to check the download is what they expected and, if they hit "yes, it's fine" then update the database. Edited: in response to OP's comment. 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. Viewed 30k times. The basename function is used to retrieve the filename, and the filesize function is used to read the size of the file in bytes, which will be shown in the opening dialog box to download the file. The flush function is used to clear the output buffer. The readfile function is used with the filename only, here.

Output The following output will appear after clicking the download link of the image file. The file size of the rose. You can download the file by selecting the Save File radio button and pressing the OK button. If the file exists at the given file location, the file path will be required to mention in the URL. In this example, we will create an HTML file with the following code, which will pass the filename with the file path:.

We will create a PHP file with the following code to download a file from the file path. The PHP code in the previous example will be slightly modified to download the file from the given path. The clearstatecache function is used to clear the cache that was previously stored. Two arguments are used in the readfile function. Output After the download link of the PDF file is clicked, the following output will appear.

I don't want to remove files that shouldn't be removed. But thanks for your help and answers! Strangely enough, this doesn't work either I have 3 files: a With a chunksize of 1 byte, it doens't continue for a and b, but still does for c. So the script would still conclude that it was downloaded even if cancel was clicked. If anyone has an idea how this works and how I could get a script to correctly report whether a file was actually downloaded or not, please let me know.

This discussion thread is closed Start new discussion. Similar topics Javascript. Check file size of photos using Javascript. How I can check file existence including subfolders. How to check file exist using c language. Upload file Check file size. Visual Basic. NET Framework. Check file for write access before opening with a TextWriter.

File downloaded as 'download. Check File Size using JavaScript. A tool to try open-source projects quickly. Get Ahead by Going Headless. Achieving a true 3-Tiered Architecture through Load Balancing. Online Marketing. Anyone used Google's 5 stars reviews? I had a good ideia of a image transition but I don't know to implement because it's away from my knowledge.

How to make game bots for chat rooms? Prime numbers.



0コメント

  • 1000 / 1000