luca 8d5786295a Patch level :
Files correlati     :
Ricompilazione Demo : [ ]
Commento            : Modifiche di marco


git-svn-id: svn://10.65.10.50/trunk@8858 c028cbd2-c16b-5b4b-a496-9718f37d4682
2000-03-02 15:26:30 +00:00

129 lines
3.4 KiB
Perl
Executable File

#!/usr/bin/perl -w
# Copyright (c) 1996 Steven E. Brenner
# $Id: upload.pl,v 1.1 2000-03-02 15:26:30 luca Exp $
require 5.001;
use strict;
require "./cgi-lib.pl";
require "./HyperNews/.scripts/check_mod_user.pl";
MAIN:
{
my (%cgi_data, # The form data
%cgi_cfn, # The uploaded file(s) client-provided name(s)
%cgi_ct, # The uploaded file(s) content-type(s). These are
# set by the user's browser and may be unreliable
%cgi_sfn, # The uploaded file(s) name(s) on the server (this machine)
$ret, # Return value of the ReadParse call.
$user, # User name from environment
$course, # Course name selected from user database
$basedir, # Base directory for download (per evitare i cheats)
$fn, # File per le note dell'utente
$fl, # nome del file in locale
$xn,
$ccc,
$i1,
$i2
);
# When writing files, several options can be set..
# Spool the files to the /tmp directory
#$basedir = "../upload/";
$basedir = "../corso_";
$user = $ENV{'REMOTE_USER'};
$course = get_course($user);
$cgi_lib::writefiles = "/tmp";
$basedir = "$basedir$course/upload/";
$user = "$basedir$user";
if (!-d $user) {
mkdir $user, 0755;
}
$cgi_lib::writefiles = $user;
# Limit upload size to avoid using too much memory
$cgi_lib::maxdata = 500000;
# Start off by reading and parsing the data. Save the return value.
# Pass references to retreive the data, the filenames, and the content-type
$ret = &ReadParse(\%cgi_data,\%cgi_cfn,\%cgi_ct,\%cgi_sfn);
# A bit of error checking never hurt anyone
if (!defined $ret) {
&CgiDie("Errore in lettura parametri del CGI");
} elsif (!$ret or !defined $cgi_data{'upfile'} or !defined $cgi_data{'note'}) {
# Legge il file upload.htm dal direttorio dei servizi
# e lo restituisce così com'è
print "Content-type: text/html\n\n";
$xn = "../servizi/upload.htm";
open (FKL, $xn);
while (!eof(FKL)) {
$ccc = getc(FKL);
print $ccc;
}
close (FKL);
exit 1;
}
if ($user eq '') {
&CgiDie("Utente non autorizzato\n",
"Si prega di effettuare ancora la validazione dell'utente.\n");
}
if (!-d $basedir) {
&CgiDie("Impossibile trovare il direttorio base per l'upload\n",
"Contattare il docente.\n");
}
if ($cgi_cfn{'upfile'} eq '') {
&CgiDie("Nome file non valido\n",
"Assicurarsi di aver fornito un nome file corretto.\n");
}
$fn = ">>$user/note.txt";
open (FILE, $fn) || &CgiDie("Impossibile aprire il file delle note $fn\n");
binmode (FILE); # write files accurately
print FILE "---- Nota ----\n";
print FILE $cgi_data{'note'} ;
# print FILE "\n---- Fine nota ----\n";
print FILE "\n";
close (FILE);
$i1 = rindex($cgi_cfn{'upfile'}, "\\");
$i2 = rindex($cgi_cfn{'upfile'}, "/");
if ($i2 > $i1) {
$i1 = $i2;
}
$fl = "$user/";
if ($i1 > -1) {
$fl .= substr($cgi_cfn{'upfile'}, $i1+1);
} else {
$fl .= $cgi_cfn{'upfile'};
}
# Cambia nome
rename ($cgi_sfn{'upfile'}, $fl) ;
# Now print the page for the user to see...
print &PrintHeader;
print &HtmlTop("Invio file");
print <<EOT;
Il file <i>$cgi_cfn{'upfile'}</i> e' stato ricevuto.<br>
<b>Grazie.</b>
<hr>
EOT
print &HtmlBot;
# The following lines are solely to suppress 'only used once' warnings
$cgi_lib::writefiles = $cgi_lib::writefiles;
$cgi_lib::maxdata = $cgi_lib::maxdata;
}