xcoderx Posted November 15, 2009 Share Posted November 15, 2009 guys by any means is it possible i could add a time limit for a file to get deleted here $content = 'messages/'.$file.'.txt'; unlink($content); say i want the file to get deleted after 1 minute after the person reach the link Quote Link to comment https://forums.phpfreaks.com/topic/181616-setting-up-a-time-for-unlink/ Share on other sites More sharing options...
Daniel0 Posted November 15, 2009 Share Posted November 15, 2009 You can use at on Linux. It's essentially a one-time cronjob. Quote Link to comment https://forums.phpfreaks.com/topic/181616-setting-up-a-time-for-unlink/#findComment-957961 Share on other sites More sharing options...
mrMarcus Posted November 15, 2009 Share Posted November 15, 2009 a very simple way would be using AJAX (jQuery/MooTools) .. with AJAX, you can set a timer to execute a file of your choice asynchronously on the server. that file could be to delete a file, or whatever you like. it could work like such: person reaches link/page; countdown timer commences; 0 is reached, AJAX runs unlink.php?file=file_to_be_removed.txt; i have no idea how your system is setup, but anytime you are dealing with deleting files, etc., security is crucial. Quote Link to comment https://forums.phpfreaks.com/topic/181616-setting-up-a-time-for-unlink/#findComment-957962 Share on other sites More sharing options...
Daniel0 Posted November 15, 2009 Share Posted November 15, 2009 it could work like such: person reaches link/page; countdown timer commences; 0 is reached, AJAX runs unlink.php?file=file_to_be_removed.txt; Won't work if the user leaves the page before a minute has passed. Quote Link to comment https://forums.phpfreaks.com/topic/181616-setting-up-a-time-for-unlink/#findComment-957963 Share on other sites More sharing options...
xcoderx Posted November 15, 2009 Author Share Posted November 15, 2009 guess i got to use some session crap? Quote Link to comment https://forums.phpfreaks.com/topic/181616-setting-up-a-time-for-unlink/#findComment-957968 Share on other sites More sharing options...
mrMarcus Posted November 15, 2009 Share Posted November 15, 2009 i know you can write a CRON job with PHP. i've never played around with it, but you could use it to write a cron to be execute 1 minute from that point in time, and have the cron run you deletion script/file. need to be able to use exec() on your server. Quote Link to comment https://forums.phpfreaks.com/topic/181616-setting-up-a-time-for-unlink/#findComment-957983 Share on other sites More sharing options...
xcoderx Posted November 16, 2009 Author Share Posted November 16, 2009 something like this would work? $content = 'messages/'.$file.'.txt' -mmin -60 -exec rm -f {} \; unlink($content); Quote Link to comment https://forums.phpfreaks.com/topic/181616-setting-up-a-time-for-unlink/#findComment-958347 Share on other sites More sharing options...
xcoderx Posted November 16, 2009 Author Share Posted November 16, 2009 i get this error message Parse error: syntax error, unexpected T_STRING in /home2/public_html/0.php on line 190 Quote Link to comment https://forums.phpfreaks.com/topic/181616-setting-up-a-time-for-unlink/#findComment-958349 Share on other sites More sharing options...
Daniel0 Posted November 16, 2009 Share Posted November 16, 2009 If you're going to use the command line, why not just use at like I already suggested? Quote Link to comment https://forums.phpfreaks.com/topic/181616-setting-up-a-time-for-unlink/#findComment-958352 Share on other sites More sharing options...
dreamwest Posted November 16, 2009 Share Posted November 16, 2009 filemtime() Quote Link to comment https://forums.phpfreaks.com/topic/181616-setting-up-a-time-for-unlink/#findComment-958357 Share on other sites More sharing options...
xcoderx Posted November 16, 2009 Author Share Posted November 16, 2009 daniel bro with @ i get Warning: Unexpected character in input: ''' (ASCII=39) state=1 in Quote Link to comment https://forums.phpfreaks.com/topic/181616-setting-up-a-time-for-unlink/#findComment-958376 Share on other sites More sharing options...
Daniel0 Posted November 16, 2009 Share Posted November 16, 2009 daniel bro with @ i get Warning: Unexpected character in input: ''' (ASCII=39) state=1 in at is a unix command. Like this: daniel@daniel-laptop:~$ at -h Usage: at [-V] [-q x] [-f file] [-mldbv] timespec ... at [-V] [-q x] [-f file] [-mldbv] -t time at -c job ... atq [-V] [-q x] atrm [-V] job ... batch Quote Link to comment https://forums.phpfreaks.com/topic/181616-setting-up-a-time-for-unlink/#findComment-958378 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.