Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Question regarding basic help with my upload script

by nobull (Friar)
on Apr 03, 2005 at 12:24 UTC ( [id://444493]=note: print w/replies, xml ) Need Help??


in reply to Question regarding basic help with my upload script

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: $!"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://444493]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found