Php delete file after download
It seems that your browser does not have Javascript enabled. Msg Senior Member joined:Apr 15, posts votes: 3. Hi guys, I've got a new service on a website which involves dynamically creating a binary file which is an installation package for a user to download.
Preferred Member joined:Dec 10, posts votes: 0. Preferred Member joined:July 31, posts votes: 0. This is the code i have in my download script. It sends file by chunks, checking if connection not broken. Think you should be able to delete the file if you put "unlink" or something after this code. Senior Member from FR joined:Apr 19, posts: votes: Couldn't you base it on reading the result of a progess bar script then del when done? I have seen a bunch of those dealing with file d-loads and progress bar.
Thanks for the input guys. In order to download the file, we are going to display a list of all files and a Download button. Paste the following code in index. At this point, if you refresh index. Clicking on the Download button, will open a Download dialog based on your browser. In order to delete the file, first display a button to be clicked to delete.
Href should be the full path of the file. The following code should be inserted inside the loop, after the Download button:. Create a new file named delete. Now you will see a red button with a text Delete, on click it will delete the file and refresh the index. Computer Programmer. Full-stack developer. View all posts by adnanafzal There is no database related work in this article, it simply uploads the file and download the file.
Hi I would like to have a button where I can press it and then download all files at once as a zip file, but I want to be able to download the files individually. Collectives on Stack Overflow. Learn more. Asked 9 years, 9 months ago. Active 9 years, 3 months ago. Viewed 8k times. If any one can help me with this, I would really appreciate.
Add a comment. Active Oldest Votes. What you basically need to do is: Scan the directory with scandir Loop over it and check file creation times with filemtime to find the 'newest file' Delete all the files with unlink that have older timestamps But do remember that sometimes it is a good idea to keep files with older timestamps. Perhaps delete every file that is older than one hour and that is not the newest file.
If u cud take the snippet of my code and show me exactly as to what ur trying to say, that would be really useful. I added an example of deleting everything except the newest file. I didn't use your code for base though, but I am sure it's easy to figure out.
This would be easier if you could sort files based on modified time with scandir , it would not have to be looped twice.
Alternative is to use what user recommended, deleting all files before generating a new one, but that may not be good for some circumstances.
0コメント