in reply to filenames from filehandles

I agree with chromatic -- don't trust the client. The ability to upload .zip files named .jpg has been used to upload warez various places. In the general case, though...

if ($^O eq 'linux' and -d /proc) { $procpath=fileno($fh); $filename=readlink($procpath); $filename=undef unless -e $filename; }

note that this is linux-specific, though there is a similar proc on many unixes.


Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Replies are listed 'Best First'.
Re^2: filenames from filehandles
by ikegami (Patriarch) on Feb 06, 2009 at 17:29 UTC

    $procpath=fileno($fh);
    should be
    $procpath='/proc/self/fd/'.fileno($fh);

    Also, your directory test is missing quotes.

    my $filename; if (defined(my $fileno = fileno($fh))) { if ($^O eq 'linux') { my $procpath = "/proc/self/fd/$fileno"; $filename = readlink($procpath); $filename = undef unless -e $filename; } }