open FILE, "$file" or die "Can't open receipt page html file for display $!\n"; flock(FILE,2) or die "cannot lock file: $!"; # now make all image paths local and absolute. undef $/; # enable "slurp" mode my $line = ; # whole file now here close (FILE); $line =~ s/\n/ /g; #Strip out potentially nasty stuff. $line =~ s///sig; $line =~ s///sig; $line =~ s///sig; my ($image_path, $image_name, @images_list); foreach my $key (keys %imagefiles){ $image_name = basename($key); $image_path = dirname($key); # do some regex juju to replace old path/image name, # with new path and the same image name. if ($line =~ /$key/ig) { $line =~ s/$key/$images_url\/$image_name/ig; } else { $line =~ s/$image_name/$images_url\/$image_name/ig; } }# end of foreach. print "Content-type: text/html\n\n"; print $line; # This empties the url file after the display is successful # Since the final read doesn't alter the actual file, its # important to clear out the file after use so it can't # be accessed directly, instead of only via the script. open (FILE, ">$file"); flock(FILE,2) or die "cannot lock file: $!"; close (FILE); exit(0);