I want to get file size I’m doing this:
my $filename=$query->param("upload_file");
my $filesize = (-s $filename);
print "Size: $filesize ";`
Yet it is not working. Note that I did not upload the file. I want to check its size before uploading it. So to limit it to max of 1 MB.
You can’t know the size of something before uploading. But you can check the
Content-Lengthrequest header sent by the browser, if there is one. Then, you can decide whether or not you want to believe it. Note that theContent-Lengthwill be the length of the entire request stream, including other form fields, and not just the file upload itself. But it’s sufficient to get you a ballpark figure for conformant clients.Since you seem to be running under plain CGI, you should be able to get the request body length in
$ENV{CONTENT_LENGTH}.