Главная страница


ru.cgi.perl

 
 - RU.CGI.PERL ------------------------------------------------------------------
 From : Denis Knyazev                        2:50/551.38    12 Mar 2003  19:09:12
 To : Sergey Novikov
 Subject : upload binary file
 -------------------------------------------------------------------------------- 
 
  --==  #Sergey Novikov# /=>/ #Bugrimov Oleg S.#  ==--
 
 SN> Фpя четвеpтая, зачем ей binmode??? Hо все pавно попpобовал -
 SN> бесполезно... Может еще где чего???
 
         Hу, тогда может быть всё таки воспользоваться стандартными
         средствами CGI.pm ? Поверь на слово, я на эти грабли наступал,
         в данном случае лучше не изобретать велосипед. Вот цитата
         из perldoc CGI:
 
 When the form is processed, you can retrieve the entered filename by calling
 param():
 
        $filename = $query->param('uploaded_file');
 Different browsers will return slightly different things for the name. Some
 browsers return the filename only. Others return the full path to the file,
 using the path conventions of the user's machine. Regardless, the name returned
 is always the name of the file on the user's machine, and is unrelated to the
 name of the temporary file that CGI.pm creates during upload spooling (see
 below).
 
 The filename returned is also a file handle. You can read the contents of the
 file using standard Perl file reading calls:
 
         # Read a text file and print it out
         while (<$filename>) {
            print;
         }
         # Copy a binary file to somewhere safe
         open (OUTFILE,">>/usr/local/web/users/feedback");
         while ($bytesread=read($filename,$buffer,1024)) {
            print OUTFILE $buffer;
         }
 However, there are problems with the dual nature of the upload fields. If you
 use strict, then Perl will complain when you try to use a string as a
 filehandle. You can get around this by placing the file reading code in a block
 containing the no strict pragma. More seriously, it is possible for the remote
 user to type garbage into the upload field, in which case what you get from
 param() is not a filehandle at all, but a string.
 
 To be safe, use the upload() function (new in version 2.47). When called with
 the name of an upload field, upload() returns a filehandle, or undef if the
 parameter is not a valid filehandle.
 
      $fh = $query->upload('uploaded_file');
      while (<$fh>) {
            print;
      }
 This is the recommended idiom.
                                                 WBR, Denis.
 [#m:tg#] [#rpg#] [#gothic#] [#folk#] [#black#]
 email: denizen[at]nm.ru    ICQ UIN: 99806075
 
 --- God is Real, unless declared as Integer
  * Origin: Банальнейший артефакт (2:50/551.38)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 upload binary file   Sergey Novikov   11 Mar 2003 18:25:38 
 Re: upload binary file   Bugrimov Oleg S.   12 Mar 2003 13:34:49 
 Re: upload binary file   Sergey Novikov   12 Mar 2003 17:03:08 
 Re: upload binary file   Serge Pekarsky   12 Mar 2003 17:47:55 
 upload binary file   Denis Knyazev   12 Mar 2003 19:09:12 
 Re: upload binary file   Andrey Savitsky   12 Mar 2003 12:23:23 
 Re: upload binary file   Sergey Novikov   12 Mar 2003 17:09:46 
 Re[2]: upload binary file   Bugrimov Oleg S.   12 Mar 2003 17:49:29 
 Re: Re[2]: upload binary file   Sergey Novikov   12 Mar 2003 18:30:43 
 Re: Re[2]: upload binary file   Artem Chuprina   12 Mar 2003 22:29:20 
 Re: Re[2]: upload binary file   Sergey Novikov   13 Mar 2003 18:09:59 
 Re: Re[2]: upload binary file   Artem Chuprina   13 Mar 2003 18:50:36 
 Re: Re[2]: upload binary file   Sergey Novikov   14 Mar 2003 12:26:35 
 Re: Re[2]: upload binary file   Artem Chuprina   14 Mar 2003 13:32:09 
 Re: upload binary file   Victor Wagner   14 Mar 2003 13:43:11 
 Re: upload binary file   Sergey Novikov   14 Mar 2003 15:22:07 
 Re: upload binary file   Victor Wagner   14 Mar 2003 15:55:28 
 Re: upload binary file   Tyuvanov Boris   12 Mar 2003 18:22:18 
 Re: upload binary file   Artem Chuprina   12 Mar 2003 18:41:46 
 Re: upload binary file   Tyuvanov Boris   12 Mar 2003 18:52:32 
 Re: upload binary file   Artem Chuprina   12 Mar 2003 22:28:19 
 Re: upload binary file   Sergey Novikov   12 Mar 2003 19:20:37 
 Re: upload binary file   Sergey Novikov   12 Mar 2003 19:18:28 
 Re: upload binary file   Andrey Savitsky   12 Mar 2003 17:43:49 
 Re: upload binary file   Alex Povolotsky   14 Mar 2003 09:59:04 
Архивное /ru.cgi.perl/28093e6f4dbc.html, оценка 2 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional