The error itself should be reported in the server error log. That should be your first place to check. The code itself is syntactically correct, however, I'd error check your 'open' call. I don't know, but that extra new line might be causing you a problem. You are telling the browser to expect a binary stream and the first thing it gets is a new line. Like I said, that may, or may not be your problem. If not, then there are several ways you can accomplish the same function. One would be to print a Location: /path/to/file.exe instead of the header. That will cause most (if not all) browsers to redirect directly to the file.

If the purpose of the script is to track how many times the file is downloaded, you should move the file outside of a public directory. As it stands now, anyone that knows the direct link to the file can download, thus bypassing your logging.

Also, just for reference, a more perlish way of writing your code (not that I am endorsing your method of solving your problem, but..) it would be:

#!/usr/local/bin/perl -w use strict; my $FILE= "/home/username/cgi-bin/test/file.exe"; print "Content-Type: application/octet-stream\n\n"; open(FH, $FILE) || die "Can't access file: $_\n"; print <FH>; close(FH);

In reply to Re: code problem by erasei
in thread code problem by sandal

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.