Hello Monks,
I am working on a script that allows users to download files from a website to their computer. Unfortunately, the original file name has been stored using the name sent by the uploading browser and OS.
This means file names could be any of the following.
Examples:
Z:\my_files\docs\some_kind_of_manual.pdf
myfile.docx
/home/someguy/file.txt
My hope is to get the actual file name regardless of which operating system/browser uploaded the file. If I understand correctly, File::Basename assumes the filename is using the same operating system as the server which isn't necessarily true in this situation.
My question is: will fileparse() work properly anyway with any of these types of filenames if all I need is the $name of the file?
#!/usr/bin/perl
use strict;
use File::Basename;
use File::MMagic;
#skip some code here...
my ($name,$path,$suffix) = fileparse($filename);
my $mm = File::MMagic->new('/usr/share/file/magic');
my $mimetype = $mm->checktype_byfilename($name);
print "Content-type: $mimetype\n";
print "Content-Disposition: attachment; filename=\"$name\"\n\n";
#other code goes here to output file...
Thanks for your help.
(Running Perl 5.8.8 on Debian Etch)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.