sathya_myl has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to download a zip file using the below code.

open FROM, "<$file_name"; my $blksize = (stat FROM)[11] || 4096; my $buf; while (sysread FROM, $buf, 4096) { print $buf; } close FROM;

We have an option to lock the page(using javascript) when any process happen with in the page. Whenever i download using the above code, the page doesn't unlock or not executing javascript. I even tried other download options like printing the handler like print <FROM>, it's also creating the same problem.

My simple understading is that whenever i use a print command like print $buf or print <FROM>, it's creating the problem. Correct if i'm wrong.

Thanks in advance

Replies are listed 'Best First'.
Re: File download using mod perl
by Corion (Patriarch) on May 18, 2012 at 14:01 UTC

    Where does mod_perl come into play? Have you tried eliminating mod_perl?

    Where does Javascript come into play? Does the problem persist if you eliminate Javascript from the problem?

    What do you mean by "lock the page"? If this happens in Javascript, then this is a Javascript/browser problem, which cannot be solved with Perl on the server side.

      Thanks for the response corion. The whole page is designed using mod_perl. The page lock refers to displaying a small alert saying "operation in progress". You can't execute any other work until the previous request is completed.

      Whenever i tried to execute a javascript without download code, the page is responding as expected. But when i include the download code into the script, that's creating the issue.

        There is no easy way to do two things at once with HTTP. I recommend you learn about HTTP and do not "lock the page" at all then.

        Also read Watching Long Processes Through CGI for an idea how you could still have the "operation in progress" thing on the page. But note that most browsers will show a separate progress bar for the download anyway. There is no need to block the user from working with your website just because a download is in progress.