I may be missing the point altogether, but you might not want to have the path listed at all. Instead, put in a cgi script that takes the web dir path and returns the image from the real path. That is, the URL
http://mysite.com/cgi-bin/get-image/image1.jpg
would execute the cgi-bin script "get-image" w/ a PATH_INFO (?) env var ($ENV{PATH_INFO in your script) of "/image1.jpg". At that point, get-image can do any sort of security/un-tainting (e.g.
my $path-info = $ENV{PATH_INFO} my $path = "/home/usrs/rjoseph/images"; $path-info =~ s/^[^/]// # strip of preceeding noise $path-info =~ s#[^/\w\.]//g # strip out any non-word dot chars
and then say:
my $file_path = "$path/$path-info"; if ( -s $file_path ) { open(FILE, $file_path) or die ...
So if you're writing back URLs to your web users, you can do:
foreach my $file ( @image_list ) { $file =~ s#$path##; # remove the physical path part my $file_name = $file; $file_name = s/\.\w+$//; # strip off extension print "<a href=\"http://mysite.com/cgi-bin/get-image/$file">Image: $ +file_name</a>"; }
where @image_list has your real file names in it. You may want to take a look at CGI.pm file upload freaking me out

a


In reply to Re: Stripping parts of paths from directory names by a
in thread Stripping parts of paths from directory names by r.joseph

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.