Question regarding basic help with my upload script

Good subjects are important. Please try to leave out words that do not significantly contribute to the meaning and use the space saved to add ones that do. For example, in your subject the following does not significantly contribute to the meaning: "Question regarding basic help with my ... script".

...fails to allow me to control any conditions such as:
1. set allowed ext. ie (.gif,.jpg,.jpeg)
2. control upload size. ie (max=2000)

If you want to limit the upload size to avoid a DoS attack then set $CGI::POST_MAX.

If you are asking how to tell the browser that you want it to restrict what it invites the user to upload then you need to look at the HTML of the upload form, not the CGI script that processes the HTTP submission afterwards. (This has nothing to do with Perl).

If you are asking how to check if a string ends with a particular sequence of characters then perhaps something like:

$filename =~ /\.(gif|jpg|jpeg)$/

If you are asking how to tell how big a file associated with a filehandle is then you could use something like:

-s $file
anything you may feel I should also consider
open(OUT, ">$upload_dir/$filename") || die print "Fail to upload: $!"; + while(<$file>) { print OUT; } close(OUT);
You should consider that the fact that GIF and JPEG are binary formats.

As such you should put the OUT filehandle into binary mode. Also you should not try to copy the file a line of text at the time - because it is not made up of lines of text.

{ local *OUT; # Or better yet use lexical filehandle! open(OUT, ">$upload_dir/$filename") or die "Fail to open $filename: + $!"; binmode(OUT); local $/=\1024; # A block at a time local *_; # Don't stomp on $_ while(<$file>) { print OUT; } close(OUT) or die "Error writing $filename: $!"; }

In reply to Re: Question regarding basic help with my upload script by nobull
in thread Question regarding basic help with my upload script by tf198

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.