Hi Monks!

I would like to have your advice on the following problem:

I am making a small webapp and my purpose is to create a number of text files, compress them, download as zip file and erase.

For the moment I've been able to create the directory with the file, put them in a zip file and to download, but I can't erase the zip file. Well..It's not totally true. The problem is that if I do it, it compromises the download. My question would then be : Ho can I postpone the file elimination or, how can I check that the file has been totally completed before I erase it?

I know about the existence of File::Temp, but as I need this zip file just once, I think it would be simpler to just delete it. Here is a part of the code

sub write_and_download{ [...] $self->generate_zip(); $self->download_file(); my $filename = "temporary/" . $projectname . ".zip"; unlink $filename; }; sub download_file{ my $self = shift; my $downloadfile = $projectname . ".zip"; my $fullpathdownloadfile = "temporary/$downloadfile"; my $output = ''; my $buffer = ''; open my $fh, '<', $fullpathdownloadfile or return error_handler("Error: Failed to download file <b>$down +loadfile</b>:<br>$!<br>"); while (my $bytesread = read($fh, $buffer, 1024)) { $output .= $buffer; } close $fh or return error_handler("Error: Failed to download file <b>$down +loadfile<b>:<br>$!<br>"); my $downloadfilesize = (stat($fullpathdownloadfile))[7] or return error_handler("Error: Failed to get file size for <b>$ +downloadfile<b>:<br>$!<br>"); $self->header_props( '-type' => 'application/x-downl +oad', '-content-disposition' => "attachment;filename +=$downloadfile", '-content_length' => $downloadfilesize, ); return $output; };

I thank you from now for your help


In reply to cgi download and delete file by teddyttas

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.