[Cedarvalley] upload problem

Aaron Thompson thompson at cns.uni.edu
Fri Dec 19 09:42:29 CST 2003


The problem seems to be that it doesn't work with Mozilla 1.5 or IE 6 but works
fine with NS 4.7 (I don't have a copy of a new NS browser to test with).

Here is the code/html:

Thanks for your help.


-----<perl>-----
...
sub upload_file{
  my $overwrite = "1"; #overwrite files on upload (yes = 1, no = 0)
  my $length = 0;
  my $file = $query->param("upload-me");
  my $local_file_name = "";
  my $uploadFH;
  my $save_flag;

  $file =~ s/.*[\/\\](.*)/$1/;
  $local_file_name = $tmp_dir . "/" .$file;
  print "<p>File Upload...<br>This may take some time, please wait...</p>";
  print "<p>Attempting to upload: $file</p>";
  $save_flag = 1;
  if(! $overwrite){if( -e $local_file_name ){$save_flag = 0;}}#fi
  if($save_flag){
    $uploadFH = $query->upload("upload-me");
    open UPLOADFILE, ">$local_file_name" or
     html_die("Could not open $local_file_name for writing!");
      binmode UPLOADFILE;
      while ( <$uploadFH> ){
        print UPLOADFILE;
        $length += length($_);
      }#elihw
    close UPLOADFILE;
    print "<p><b>$file</b> of size <b>$length bytes</b> was uploaded.</p>";
  }
  else{
    print "<p><b>$file</b> already exists... could not upload.</p>";
  }#fi
}
...
-----<perl>-----

-----<HTML>-----
<html>
    <head>
      <title>server.domain</title>

      <script language="javascript">

      function sure(){
        msg="Are you sure you want upload this file?";
        return (confirm(msg));
      }//erus
</script>
      
    </head>
    <body>
      <table width="50%" border="1" align="center">
      <tr>
        <td align="center"><b>Upload a gallery for aaron</b></td>
      </tr>
      <tr><td></td></tr>
      <tr><td></td></tr>
      <tr>
        <td>
          <b>NOTE:</b> The following limitations will apply when using this tool...
          <ul>
            <li>this will only work with .zip files</li>
            <li>you should not have any spaces in your image files or zip file.</li>
            <li>Once you agree to send the data nothing will display untill the transfer is complete.</li>
          </ul>
          <br>
          <form action="http://server.domain/admin/index.cgi" methd="post" ENCTYPE="multipart/form-data">
            <input type="hidden" name="option" value="add-galleries">
            <input type="hidden" name="function" value="upload-gallery">
            <input type="hidden" name="gallery" value="test_gallery">
            <table border="0" width="95%" align="center">
            <tr>
              <td align="right">upload file:</td>
              <td><input type="file" name="upload-me"></td>
            </tr>
            </table>
            <div align="center">
              <input type="submit" name="submit" value="submit" onclick="return sure();">
            </div>
          </form>
        </td>
      </tr>
      <tr><td></td></tr>
      <tr><td></td></tr>
      <tr>
        <td align="center">
          <a href="http://server.domain/admin/index.cgi?option=edit-galleries">Edit Galleries</a>
        </td>
      </tr>
      </table>
    </body>
</html>
-----<HTML>-----



On Wed, Dec 17, 2003 at 04:08:58PM -0600, Stephen D. Wells wrote:
> If I understand you right it works with netscape but not mozilla...  Do
> you have a small complete example (including your html) somewhere?
> 
> STEVE
> 
> On Wed, 2003-12-17 at 11:15, Aaron Thompson wrote:
> > oh yes... I'm not quite sure what I'm doing wrong.
> > 
> > @
> > 
> > On Wed, Dec 17, 2003 at 11:10:27AM -0600, Stephen D. Wells wrote:
> > > I'm back home now and can email again... for some reason the web-based
> > > mailer I was using wasn't sending out - I'm back to evolution now though
> > > and things are back to normal.  Is this still an issue?
> > > 
> > > STEVE
> > > 
> > > On Thu, 2003-12-11 at 13:52, Aaron Thompson wrote:
> > > > I have been looking and found that I get different data when
> > > > using mozilla 1.5 or Netscape 4... it seems like I don't get 
> > > > everything...  well... back to reading.
> > > > 
> > > > Netscape:
> > > > 
> > > > $VAR1 = bless( {
> > > >                  '.charset' => 'ISO-8859-1',
> > > >                  'upload-me' => [
> > > >                                   bless( \*{'Fh::fh00001new_gallery.zip'}, 'Fh' )
> > > >                                 ],
> > > >                  'submit' => [
> > > >                                'submit'
> > > >                              ],
> > > >                  'option' => [
> > > >                                'add-galleries'
> > > >                              ],
> > > >                  'gallery' => [
> > > >                                 'New_Gallery'
> > > >                               ],
> > > >                  'function' => [
> > > >                                  'upload-gallery'
> > > >                                ],
> > > >                  '.tmpfiles' => {
> > > >                                   '6' => {
> > > >                                            'info' => {
> > > >                                                        'Content-Disposition' => 'form-data; name="upload-me"; filename="new_gallery.zip"',
> > > >                                                        'Content-Type' => 'application/x-zip-compressed'
> > > >                                                      },
> > > >                                            'name' => bless( do{\(my $o = '/var/tmp/CGItemp443')}, 'TempFile' )
> > > >                                          }
> > > >                                 },
> > > >                  '.parameters' => [
> > > >                                     'option',
> > > >                                     'function',
> > > >                                     'gallery',
> > > >                                     'upload-me',
> > > >                                     'submit'
> > > >                                   ],
> > > >                  '.fieldnames' => {}
> > > >                }, 'CGI' );
> > > > 
> > > > Mozilla 1.5:
> > > > 
> > > > $VAR1 = bless( {
> > > >                  '.charset' => 'ISO-8859-1',
> > > >                  'upload-me' => [
> > > >                                   'new_gallery.zip'
> > > >                                 ],
> > > >                  'submit' => [
> > > >                                'submit'
> > > >                              ],
> > > >                  'option' => [
> > > >                                'add-galleries'
> > > >                              ],
> > > >                  'gallery' => [
> > > >                                 'New_Gallery'
> > > >                               ],
> > > >                  'function' => [
> > > >                                  'upload-gallery'
> > > >                                ],
> > > >                  '.parameters' => [
> > > >                                     'option',
> > > >                                     'function',
> > > >                                     'gallery',
> > > >                                     'upload-me',
> > > >                                     'submit'
> > > >                                   ],
> > > >                  '.fieldnames' => {}
> > > >                }, 'CGI' );
> > > > 
> > > > 
> > > > On Thu, Dec 11, 2003 at 10:54:13AM -0600, Aaron Thompson wrote:
> > > > > I'm using CGI to upload a file... the file box is 'upload-me' and the code
> > > > > below works for Netscape 4, but not Mozilla 1.5 or IE 6.  Anyone have
> > > > > experience with this and can point me in the right direction?
> > > > > 
> > > > > Error message (from apache error log):
> > > > >  Use of uninitialized value in <HANDLE> at /home/httpd/photos/admin/index.cgi line 59.
> > > > >  readline() on unopened filehandle at /home/httpd/photos/admin/index.cgi line 59.
> > > > > 
> > > > > 
> > > > > the offending code:
> > > > > ---<snip>---
> > > > > use CGI;
> > > > > ...
> > > > > 
> > > > > $query = new CGI:
> > > > > ...
> > > > > 
> > > > > ######################################################################
> > > > > sub upload_file{
> > > > >   my $overwrite = "0"; #overwrite files on upload (yes = 1, no = 0)
> > > > >   my %valid_mime = ("zip" => "1");
> > > > >   my $length = 0;
> > > > >   my $file = $query->param("upload-me");
> > > > >   my $local_file_name = "";
> > > > >   my $uploadFH; 
> > > > >   my $mime;
> > > > >   my $save_flag;
> > > > > 
> > > > >   $file =~ s/.*[\/\\](.*)/$1/;
> > > > >   if($file =~ /.*[\.](.*)/){$mime = $1;}#fi
> > > > >   $local_file_name = $tmp_dir . "/" .$file;
> > > > >   print "<p>File Upload...<br>This may take some time, please wait...</p>";
> > > > >   print "<p>Attempting to upload: $file</p>";
> > > > >   if ($valid_mime{$mime}){
> > > > >     $save_flag = 1;
> > > > >     if(! $overwrite){if( -e $local_file_name ){$save_flag = 0;}}#fi
> > > > >     if($save_flag){
> > > > >       $uploadFH = $query->upload("upload-me");
> > > > >       open UPLOADFILE, ">$local_file_name" or
> > > > >         html_die("Could not open $local_file_name for writing!");
> > > > >         binmode UPLOADFILE;
> > > > >         while ( <$uploadFH> ){
> > > > >           print UPLOADFILE;
> > > > >           $length += length($_);
> > > > >         }#elihw
> > > > >       close UPLOADFILE;
> > > > >       print "<p><b>$file</b> of size <b>$length bytes</b> was uploaded.</p>";
> > > > >     }else{
> > > > >       print "<p><b>$file</b> already exists on the server - not uploaded. </p>";
> > > > >     }#fi
> > > > >   }
> > > > >   else{
> > > > >     print "<p>File not saved... unallowed file time: $mime</p>";
> > > > >   }#fi
> > > > > }
> > > > > 
> > > > > ---<snip>---
> > > > > 
> > > > > Thanks for your help.
> > > > > 
> > > > > @
> > > > > 
> > > > > 
> > > > > -- 
> > > > > Aaron Thompson   Unix Systems Administrator, College of Natural Science
> > > > > University of Northern Iowa                      Cedar Falls, IA  50614
> > > > > 
> > > > > "Because as we know, there are known knowns, there are things we know we
> > > > > know. We also know there are known unknowns; that is to say we know there are
> > > > > some things we do not know. But there are also unknown unknowns - the ones we
> > > > > don't know we don't know." - Donald Rumsfeld
> > > > > _______________________________________________
> > > > > Cedarvalley mailing list
> > > > > Cedarvalley at mail.pm.org
> > > > > http://mail.pm.org/mailman/listinfo/cedarvalley
> > > -- 
> > > Stephen D. Wells <wells at cedarnet.org>
> -- 
> Stephen D. Wells <wells at cedarnet.org>

-- 
Aaron Thompson   Unix Systems Administrator, College of Natural Science
University of Northern Iowa                      Cedar Falls, IA  50614

"If there's anything more important than my ego around, I want it caught
and shot now." -Douglas Adams



More information about the Cedarvalley mailing list