Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2023-11-29 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?