ChrisFlynn Posted February 11, 2008 Share Posted February 11, 2008 My profound apologies if this has been covered recently - if someone can post a link or even just some good search words that would be brilliant. OK, I have folders full of MP3s. I've adapted a script to dynamically these folders, and serve them to users - this works. However, now my hosting have now cut me off as their tmp files are getting full and they have to clean them. I'm guessing what is happening is people are pressing 'cancel' during the download and my script is being terminated since the interaction with the user is termitated? I added a try/catch but this didn't work (I'm more familiar with Java, so don't know if it works in the same context). Could anyone see any solutions? (I have limited disc space, so need to create ZIPs 'on the fly'). <?PHP $filename_no_ext=$_GET['download']; if (!is_dir($filename_no_ext)) { echo 'Folder not found'; die(); } header("Content-Type: archive/zip"); header("Content-Disposition: attachment; filename=$filename_no_ext".".zip"); $tmp_zip = tempnam ("tmp", "tempname") . ".zip"; `zip -r $tmp_zip $filename_no_ext`; $filesize = filesize($tmp_zip); header("Content-Length: $filesize"); try { $fp = fopen("$tmp_zip","r"); echo fpassthru($fp); } catch (Exception $e) { `rm $tmp_zip `; } // clean up the tmp zip file `rm $tmp_zip `; ?> Any obvious solutions of how to fix this? Link to comment https://forums.phpfreaks.com/topic/90527-cleaning-up-failed-downloads/ Share on other sites More sharing options...
cooldude832 Posted February 11, 2008 Share Posted February 11, 2008 Don't make a real file. This is a mod on what you have, but it will work for flat files just a bit tweaking 1) Store the binaries of files in MySQL as Blobs 2) On demand from a user create the files neeed (i.e set headers for the proper content type and insert the mysql data into the doc) The document doesn't exist for say, its just executing a large php document that is streamed as an attachment. Thus no file to delete because it isn't there. If you want to keep your method I'd suggest using temp names that are of TIMESTAMP_RandNum and build a cron to say delete all files that have file names older than X hours old. It will keep it cleaner, but not perfect. Link to comment https://forums.phpfreaks.com/topic/90527-cleaning-up-failed-downloads/#findComment-464137 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.