#!/usr/bin/perl # use Apache::Constants ':common'; # homedir is /sp12/brudy/.html # if the file exists, cat it, otherwise, wait for the file to be ready, # then cat it. my $filename = "/home/brudy/public_html/images/newpicture.jpg"; my $offlinefilename = "/home/brudy/public_html/images/offline.jpg"; my $indexcounter = 0; my $sleepinterval = 1; my $done = 0; my $r = Apache->request; $r->content_type("image/jpeg"); # file exists, non-zero length if (-s $filename) { #print "Content-Type: image\/jpeg\n\n"; $r->send_http_header; # cat the file #print `cat $filename`; $r->print(`cat $filename`); } else { while (!(-s $filename) && !($done)) { # sleep for a while select(undef,undef,undef,(1/$sleepinterval)); $indexcounter++; if ($indexcounter > 10) { #print "Content-Type: image\/jpeg\n\n"; $r->send_http_header; # Send the offline image #print `cat $offlinefilename`; $r->print(`cat $offlinefilename`); $done = 1; } } }