Schrift
[thread]11257[/thread]

datei upload anhand indexes



<< >> 2 Einträge, 1 Seite
Gast Gast
 2008-02-06 17:22
#105650 #105650
Hallo!
Mal frage: ich möchte ein Datei im server anhand nur sein index laden; d.h Im server liegt beispielweise ein datei mit name "myfile_I.xls" ; anhand "I" möchte ich dieses datei öffnen.
Wie geht es mit eine Perl/CGI skript? ich habe folgende probiert aber es läuft nicht:
Code: (dl )
1
2
3
4
5
6
7
use Cwd;
$MyPlace = cwd();
opendir(DIR, $MyPlace)|| die "Error";
while ( my $File = readdir(DIR)) {
push(@Files, $File) if (!-d $File && $File =~/I/i);
}
closedir (DIR);

Vielen Dank.
Linuxer
 2008-02-06 20:27
#105661 #105661
User since
2006-01-27
3870 Artikel
HausmeisterIn

user image
Schnellschuß:

Code (perl): (dl )
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
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw( :standard );
use File::Spec::Functions;
use Cwd;


my $cgi = CGI->new();

my $index = $cgi->param('index');


my @files = find_files_by_index( $index );


print "index: $index\n@files", $/;


sub find_files_by_index {
        my $idx   = shift;
        my $dir   = cwd();
        my @files = ();

        opendir my $dh, $dir or die "$dir: $!\n";

        while ( my $file = readdir $dh ) {
                my $fullpath = catfile( $dir, $file );
                if ( !-d $fullpath and $file =~ m/_${idx}.[^.]+\z/ ) {
                        push @files, $file;
                }
        }

        closedir $dh;

        return @files;
}


Getestet auf der Kommandozeile:
Quote
> dir
bla_I.xls blubb_i.xls nix_is.txt skript.pl
> perl skript.pl index=I
index: I
bla_I.xls
> perl skript.pl index=is
index: is
nix_is.txt
>


Fuer einen Test als CGI-Skript eines Webservers fehlen ein paar Sachen.
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!
<< >> 2 Einträge, 1 Seite



View all threads created 2008-02-06 17:22.