[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

THTTPD + Web File Upload



Hi,
i am switching from suse to debian and would say debian is great :-).
I want to upload files from my workstation to the server, without using
an ftp-server. So i have combined some perl examples for an web upload
script and it works fine under suse with apache and thttpd (2.20), but
under debian with thttpd (2.21b) it fails. The file is created but with
zero bytes. Also i have problems with the form action, "get" is working
fine but replacing it with "post" nothing happens. There are no error
messages in thttpd.log or displayed on the web page. I have used the
same thttpd options from suse, without success. I hope someone can help.

Thanks in advance.

Below are the html and perl script, but i think there are no errors:
HTML
<form action="http://ns.intern.home.de/cgi-bin/upload.cgi"; method="post"
enctype="multipart/form-data">
<input type="file" name="myfile" accept="text/*" maxlength="2097152">
<input type="submit"><input type="reset">
</form>

PERL-CGI
#!/usr/bin/suidperl -Tw
use strict;
use CGI; # Modul fuer CGI-Programme
use CGI::Carp ('fatalsToBrowser');
my $dest='/usr/local/httpd/htdocs/config.cs';

# neues Objekt erstellen
my $cgi = new CGI;

# die datei-daten holen
my $file = $cgi->param("myfile");

sub msg {
 print ("<h1>@_</h1>");
 print ("</body>");
 print ("</html>");
 exit;
}

# HTML-Seite beginnen
print ("Content-Type: text/html\n\n");
print ("<HTML><HEAD><TITLE>File Upload</TITLE></HEAD><BODY>");

# Fehlerprüfung
unless ($file) {
 msg("Error: Empty Filename!");
}

unless ($file =~ /^([a-z]?:?\\?|\\?\\?)[\S]+?.fw$/i) {
 msg("Error: Bad Filename/ Path");
}

# dateinamen erstellen und die datei auf dem server speichern
my $fname = $dest;
open DAT,'>'.$fname or msg("Fehler beim speichern");

# Dateien in den Binaer-Modus schalten
binmode $file;
binmode DAT;

my $data;
while(read $file,$data,1024) {
  print DAT $data;
}
close DAT;

if (!-s "/usr/local/httpd/htdocs/config.cs") {
 unlink("/usr/local/httpd/htdocs/config.cs");
 msg ("Datei leer!");
}

msg("Upload successfully");





Reply to: