strange behavior when using 'read'

Discussion in 'Perl' started by sstark, Mar 6, 2005.

  1. sstark

    sstark Guest

    Hi, I have a web/cgi script that allows users to upload a file to the
    web server. I want to only allow files up to a certain size, which is
    stored in $imageFileMaxSize (typically 75K). That part works correctly,
    i.e. the script does not allow uploads larger than $imageFileMaxSize.

    The problem is, when a user attempts to upload a file larger than
    $imageFileMaxSize, the on_error routine is not called; instead the
    script reloads from its starting point, with no message. My users find
    this confusing, sometimes thinking the file has been uploaded,
    sometimes getting frustrated and trying again.

    How can I get on_error to display the proper message? Here's my code:

    $imageFileMaxSize = 75000;
    $CGI::pOST_MAX = $imageFileMaxSize;

    sub create_new_image_file {
    my $newImageFile = @_;

    $file = param('imagefile');

    open (SAVE, ">$newImageFilenamePath")");
    while (read($file,$data,1024)) {
    print SAVE $data;
    $imageFileLength += length($data);
    on_error("Image file is too large; maximum size allowed is
    $imageFileMaxSize") if($imageFileLength > $imageFileMaxSize);
    }
    close(SAVE);
    on_error("File was not received; check filename.") if($imageFileLength
    < 1);

    }

    thanks!
    Scott
    sstark, Mar 6, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Z21hcnF1ZXo=?=

    Strange behavior using SSL and "FORMS" authentication.

    =?Utf-8?B?Z21hcnF1ZXo=?=, Jan 6, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    631
    Hermit Dave
    Jan 6, 2004
  2. _v_tiziano
    Replies:
    0
    Views:
    418
    _v_tiziano
    Jan 16, 2006
  3. Nicholas Palmer

    Strange behavior when using AspCompat=true

    Nicholas Palmer, Jan 22, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    526
    Nicholas Palmer
    Jan 23, 2007
  4. Mudcat
    Replies:
    5
    Views:
    331
    Eric Brunel
    Nov 15, 2006
  5. gmarquez
    Replies:
    2
    Views:
    123
    Paul Glavich
    Jan 7, 2004
Loading...

Share This Page