Hello All,

I have a funky file upload function problem -

yes, I've looked all over the hallowed halls for an answer, but none has presented itself. Putting security issuses aside (this is for an internal, password protected section of a site) here is the jist of the script, its pretty cut and dry:

sub _file_upload { my $self = shift; no strict 'refs'; foreach(@_) { my $file = $_; if ($file ne "") { my $fileName = $file; $fileName =~ s!^.*(\\|\/)!!; open (OUTFILE, ">$img_dir/$fileName") or die("can't write ima +ge file '$img_dir/$fileName': $!"); while (my $bytesread = read($file, my $buffer, 1024)) { print OUTFILE $buffer; } close (OUTFILE); } } }

the above code works well... IF the filename only has numbers in it!, like 1.gif, 2.gif, 3.gif.. ect. It won't work for filenames like photo.gif, things like that.

What is going on here? I've traced this myself to a few things:

First off, the function is screwing up in the while loop. File is created, nothing is written and the file is closed.

I don't understand where/how $file is being read. Its gotta be in the /tmp directory. Maybe something's getting messed up when I'm passing the filehandle from a script that uses the CGI.pm to get the saved form information to the Perl Module (the code above) that houses the _file_upload() function.

the above code works 100% correctly on one server that I test, which is runing suEXEC, but is otherwise a similar setup to another server that's only correctly saving files that are numbers.

Anyways, why would the name of the file make any difference?

 

-justin simoni
!skazat!


In reply to YAF(ile)U(ploading)Q(uestion) by skazat

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.