PDA

View Full Version : Forcing download of file problems


sarah_anne
07-14-2005, 10:15 AM
Hi guys,

I wasn't sure whether to post this in Perl, Misc SS, or General web building as it's a bit of a crossover, but figured that since it's a Perl-driven app I'm playing with I may as well put it here ;)

I have a cgi script that simply outputs a directory/file listing of a root folder -- note that the Perl script is running on an intranet (*nix Y: drive) but the output listing is from something like K:/projects/stuff which has various subdirectories too.

I'd like users to be able to download the files they see, so have placed a link to be displayed next to the filename saying "Download", which looks like "file://csldc01/projects/stuff/Internal%20Bulletins/Misc/Bhist%20operation.doc" (notice I've had to use the drive name here).

PROBLEM:
When viewed in IE and you click on this link, it automatically opens Word/pdf viewer/etc and displays the file. That's great.
When viewed in IE and you right click on this link, there is the option to Save Target As, which preserves everything well. That's cool too.

However, in firefox if it sees a link like "file://csldc01/projects/stuff/Internal%20Bulletins/Misc/Bhist%20operation.doc" and the user clicks on it, nothing happens at all!

To get around this, I tried implementing a force-download script using http://www.sitepoint.com/article/file-download-script-perl ...however this does not seem to work with files with spaces in their names ("Bhist%20operation.doc" gets saved as "Bhist" without all of its name or any extension!).

Any advice?

edit: I've tried convincing myself that I should just ask users NOT to use spaces in their filenames when adding files, but this is a poor solution and would work for, oh, a day :rolleyes:

rwedge
07-14-2005, 09:19 PM
During the upload of files, check for spaces in the file name and fix them.my $upfile = 'file://csldc01/projects/stuff/Internal Bulletins/Misc/Bhist operation.doc';
my @file = split(/\//, $upfile);
my $filename = pop @file;
$filename =~ s/ /_/g; # remove spaces
print $filename; Here are a couple of pages that may give you some ideas remove spaces from file/dir names (http://www.pigstye.net/article.php/20021122075650404/print) and Renaming (Removing Spaces in Filenames) (http://www.fxguide.com/fxtips-23.html)