in reply to Re: Re: Quick Regex question
in thread Quick Regex question

Let me explain in a little more detail what I'm trying to do. I have a form that writes to a text database. In that form, I have file upload fields that are used solely to get filenames for a photographic tour. When the names are written to the database, they have to have their paths chopped off. Those upload fields don't upload images because I couldn't get an upload script working that would upload that many images at once... The filenames are written to a text file (after having their paths chopped off) that tells what files need to be uploaded. Any path works so long as it has some folder in the path. Eg: A:\pic3.jpg would not work, whereas A:\test\pic3.jpg would.

Replies are listed 'Best First'.
Re (tilly) 4: Quick Regex question
by tilly (Archbishop) on Jan 14, 2001 at 07:44 UTC
    What was the problem getting the upload images to work? Just use CGI. To the best of my knowledge the only limits are throttles in CGI.pm and/or in the webserver that limit the size/number of uploads to avoid denial of service attacks. If those limits are a problem, they should be configurable and instructions to configure it should be in the documentation.
      Don't I wish it were that easy!!! I used CGI, but I couldn't get it working for the life of me, even after a week solid of work and trying out 5 different scripts! I finally got one that works for one file at a time without using CGI.pm, and it is stable. I gave up after getting that frustrated. One file isn't all that bad either when you have a slow connection. My web server has TERRIBLE documentation and I don't even have telnet access to it, so I have no clue what checks are in place there. Got any tested scripts that upload multiple files at once and work on both UNIX and WIN9X/NT boxes? If so, I would be really interested in seeing them.
        The following quick hack is not particularly good style, but it works here under Linux and I am not doing anything that should be unportable. I am just echoing back your input files, and it handles multiple files.
        #! /usr/local/bin/perl -T use strict; use CGI qw(:standard upload); use HTML::Entities; print header(), start_html('Upload Test'), h1('Upload Test'), start_multipart_form(), "Enter how many files to upload: ", textfield("filecount"), br(); for my $i (1..param('filecount')) { print "File $i: ", filefield(-name => "file$i"), br(); } print submit(); for my $file (sort grep /file/, param()) { print p(); my $handle = upload($file); unless (defined($handle)) { if ($file =~ /(\d+)/) { print h3("File request $1 did not return a handle\n"); } next; } print p(), h3("Uploaded $handle"), br(), "<pre>"; print encode_entities($_) while <$handle>; print "</pre>"; }
        (For the record I usually avoid writing CGI...don't laugh at what it looks like...)
        Why won't something like this work? What problems were you having with CGI?
        <form enctype='multipart/form-data' ...> <input type='file' name='file' ...> <input type='file' name='file' ...> (repeat) use CGI ':standard'; use File::Basename; foreach (param('file')) { my $basename = basename($_); $basename =~ tr/A-Za-z0-9.//cd; # strip out unwanted crap open(FILE, "> $basename") or die "$basename: $!"; print FILE <$_>; close(FILE); }
        You may have to tweak fileparse_set_fstype to match the OS of the client (see File::Basename and CGI, perhaps using $ENV{HTTP_USER_AGENT}). I haven't tested this, but is something like this what you were wanting to do?
      Don't I wish it were that easy!!! I used CGI, but I couldn't get it working for the life of me, even after a week solid of work and trying out 5 different scripts! I finally got one that works for one file at a time without using CGI.pm, and it is stable. I gave up after getting that frustrated. One file isn't all that bad either when you have a slow connection. My web server has TERRIBLE documentation and I don't even have telnet access to it, so I have no clue what checks are in place there. Got any tested scripts that upload multiple files at once and work on both UNIX and WIN9X/NT boxes? If so, I would be really interested in seeing them.
Re: Re: Re: Re: Quick Regex question
by I0 (Priest) on Jan 14, 2001 at 08:07 UTC
    If sounds like you just want s/.*\\// or perhaps s!.*[\\/:]!!
    But why do you say that File:Basename did not work?
      I'll try that one too, but for some reason, File::Basename wouldn't cut the path off for me. Wierd, huh?
        So in other words, that test program I posted a few nodes up gave you different results when run on your system?