Hi

1) you should do something like
my $query=new CGI(); my $filename=$query->upload("uploaded_file"); if( defined($filename) ) { # save the uploaded file open(OUTPUT, ">1.jpg"); # just an example, you should check the type binmode($filename); binmode(OUTPUT); while( read($filename, $buffer, 64*2**10) ) { # filename is a file ha +ndle here print OUTPUT $buffer; } close(OUTPUT); print $query->header(); print $filename; # it's a string here; original filename returned (th +e name on client's harddrive, fullpath/filename } else { # print the form print $query->header(); ... print $query->end_html(); }
This code was written by memory, not tested. I wrote a similar script just a few days ago. Please feel free to correct me if I'm wrong. 2) CGI.pm returns a string with an original full path/filename on client's computer when $filename is used as a string. If it's used as a file handle, a file handle is returned 3) you can get the MIME type of the uploaded file from CGI.pm. but if you want to be sure 100%, let's say, .gif is a gif actually, .jpg is a JPEG, you should check the file's content using 'file' utility thru a system call or an image-processing library like PerlMagick (ImageMagick). But it goes far away from the original question

In reply to Re: Problem with file upload CGI script by nikos
in thread Problem with file upload CGI script by reTard

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.