taint has asked for the wisdom of the Perl Monks concerning the following question:
Greetings, Monks!
I'm attempting to create temporary links (prevent "hot linking").
So what I'm attempting, is to create a symlink on initiation, and set a timer (sleep / while) that when reached, unlinks the symlink. It all works just fine, except, that it sort of "hangs" the script/web page, while the timer is counting down. I first attempted this with the sleep function. But am now trying with a while().
Here's what I have now
I'm sure this is really simple. But not for me, today. :/#!/usr/bin/perl -w use strict; use feature qw(say); use POSIX qw(strftime); my $ctime= strftime "%H-%M", localtime; my $dlfile= "../PATH_TO/SOME_FILE"; my $dlname= "SOMENAME"; my $newname= "./ANOTHER_PATH/$ctime-$dlname"; my $maxtime= 30; my $args = ('-s'); print "content-type:text/html; charset=utf-8\n\n"; say qq~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" + /> <title>Download $dlname</title> </head> <body <h1>Download $dlname</h1> ~; system("/bin/ln $args $dlfile $newname"); while ($maxtime > 0) { $maxtime--; sleep(1); say qq~<a href="$newname">download</a>~; if ($maxtime == 0) { unlink $newname; say qq~<h3>Sorry! $newname no longer exists!</h3>~; } } say qq~<p> <br /> </p> </body></html> ~; exit
Thanks, for any pointers!
--Chris
EDIT: fix a couple of typos. Move a block.
¡λɐp ʇɑəɹ⅁ ɐ əʌɐɥ puɐ ʻꜱdləɥ ꜱᴉɥʇ ədoH
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to sleep(), or use a while() in the background?
by Anonymous Monk on May 07, 2016 at 03:41 UTC | |
by taint (Chaplain) on May 07, 2016 at 08:23 UTC | |
by taint (Chaplain) on May 09, 2016 at 23:51 UTC | |
by Anonymous Monk on May 10, 2016 at 03:01 UTC | |
by taint (Chaplain) on May 07, 2016 at 06:58 UTC | |
Re: How to sleep(), or use a while() in the background?
by pryrt (Abbot) on May 10, 2016 at 01:08 UTC | |
by taint (Chaplain) on May 11, 2016 at 18:54 UTC |
Back to
Seekers of Perl Wisdom