Leser: 2
|< 1 2 3 >| | 22 Einträge, 3 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
##############################################################################
# Übergabeparameter aus Script #
##############################################################################
# my $SID = $query->param('sid');
my $action = "upload";
my $DEFAULT_UPLOAD_DIR = 'C:/htdocs/test/images/upload/';
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use strict;
use JSON;
my $query = new CGI;
my @Feldnamen = $query->param();
print $query->header(),
$query->start_html('CGI-Feedback'),
$query->h1('CGI-Feedback vom Formular');
foreach my $Feld (@Feldnamen) {
print $query->strong('Feldname: '),
$Feld,
$query->strong(', Inhalt: '),
$query->param($Feld), "<br>";
}
if($query->param() == 'true') { print "es wurde was uebermittelt<br>\n"; }
print $query->end_html();
if ($query->param('BT_Exit')) { $action = ''; }
if ($action eq 'upload') {
print $query->header;
print &Upload($query, $DEFAULT_UPLOAD_DIR);
} else {
my $url = $BACK_URL . "?error=error1";
print $query->redirect($url);
}
################################################################################
# Subs #
################################################################################
########################################
# Upload Sub #
########################################
sub Upload {
my($query, $upload_dir) = @_;
my($file_query, $file_name, $size, $buff, $time, $bytes_count);
$size = $bytes_count =0;
$_ = $file_query = $query->param('file');
s/\w://;
s/([^\/\\]+)$//;
$_ = $1;
s/\.\.+//g;
s/\s+//g;
$file_name = $_;
if (! $file_name) {
$_ = $NAME_TITLE{'EU_BadFN'};
s/Value_FileName/$file_query/ig;
&Error($_, 1);
}
if (-e "$upload_dir/$file_name") {
$_ = $NAME_TITLE{'EU_FExist'};
s/Value_FileName/$file_name/ig;
&Error($_, 1);
}
open(FILE,">$upload_dir/$file_name") || &Error("Error opening file $file_name for writing, error $!", 1);
binmode FILE;
$time=time();
while ($bytes_count = read($file_query,$buff,2096)) {
$size += $bytes_count;
#select(undef, undef, undef,0.35); # sleep for 0.35 of a second.
print FILE $buff;
}
close(FILE);
chmod (0666, "$upload_dir/$file_name");
if ((stat "$upload_dir/$file_name")[7] <= 0) {
unlink("$upload_dir/$file_name");
$_ = $NAME_TITLE{'EU_Size'};
$_ .= '{"success": false, "error": "Fehler"}';
s/Value_FileName/$file_name/ig;
&Error($_, 1);
} else {
$time = time -$time;
$_ = $NAME_TITLE{'Upload_Succes_txt'};
s/Value_FileName/$file_name/ig;
s/Value_Size/$size/ig;
s/Value_Time/$time/ig;
my $obj = '{"success": "true", "message": "Upload OK"}';
#my $json = JSON->new;
#print $json->encode($obj);
print $obj;
#&ResutPage($NAME_TITLE{'Upload_Succes'}, $_);
}
}
########################################
# Other Subs #
########################################
sub Write_Data_2_File {
my($file, $pt_arry_data) = @_;
open(FILE, ">$file") || print "Cannot write file $file, error: $!<BR>\n";
print FILE @$pt_arry_data;
close(FILE);
}
sub Read_Data_File {
my($file) = @_;
my @data;
open(FILE, "<$file") || print "Cannot open file $file, error: $!<BR>\n";
@data = <FILE>;
close(FILE);
return @data;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
#!c:/perl/bin/perl -w my $DATA_DIR='C:/htdocs/test/bigsize_images'; # Path of data directory my $DEFAULT_UPLOAD_DIR='C:/htdocs/test/images/upload'; # Path of work directory ################################################################################ # DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING # ################################################################################ use strict; use CGI; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); my $query = new CGI(); ############################################################################## # Übergabeparameter aus Formular # ############################################################################## my $SID= $query->url_param('SID'); my $action= $query->url_param('action'); my $file_name=$query->url_param('filename'); my $IMAGE_DIR='C:/htdocs/test/images/'.$query->url_param('album'); # Path of image album directory if ($query->param('BT_Exit')) { $action = ''; } if ($action eq 'upload') { print $query->header; print &Upload($query, $DEFAULT_UPLOAD_DIR, $file_name, $IMAGE_DIR); } else { print "Content-type: text/html\n\n"; print '({"success":false,"error":"No upload flag request"})'; } ######################################## # Upload Sub # ######################################## sub Upload { my($query, $upload_dir) = @_; my($file_query,$size, $buff, $time, $bytes_count); $size = $bytes_count = 0; $file_query = $query->param("file"); if (! $file_name) { &Error("Bad filename", 1); } #if (-e "$upload_dir/$file_name") { # &Error("File allready exists", 1); #} open(FILE,">$upload_dir/$file_name") || &Error("File not found!", 1); binmode FILE; $time=time(); while ($bytes_count = read($file_query,$buff,1024)) { print FILE $buff; $size += $bytes_count; } close(FILE); #chmod (0644, "$upload_dir/$file_name"); if ((stat "$upload_dir/$file_name")[7] <= 0) { unlink("$upload_dir/$file_name"); &Error("Could not open file", 1); } else { $time = time -$time; print '({"success":true})'; } } ######################################## # HTML Present subs # ######################################## sub Error { my($errortext, $exit) = @_; #print "Content-type: text/html\n\n"; print '({"success":false,"error":"'.$errortext.'"})'; if($exit) { exit; } }
1 2 3
#if (-e "$upload_dir/$file_name") { # &Error("File allready exists", 1); #}
1 2 3
if (-e "$upload_dir/$file_name") { Error("File ($upload_dir/$file_name) allready exists", 1); }
|< 1 2 3 >| | 22 Einträge, 3 Seiten |