Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

space converted to "_"

Status
Not open for further replies.

imad77

Instructor
Oct 18, 2008
97
CA
Hi,

I experience a strange issue:
I have two Perl scripts, we run the first from a web page and it diplays the files and dirctories to download, when you click on a file, it calls the second script

It displays a dialog box for download file, but it displays the name by changing the spca by "_", it dispays "test_1.txt" instead "test 1.txt"

I checked the name of the file in the system and its name is "test 1.txt", I dispayed the content of this variable $file and I gets "test 1.txt", but in the dialog box I get "test_1.txt".

Have you any idea why I get this conversion of space and "/" to "_" ?

thanks.


Here is the part of the second script:
======================

#!/usr/bin/perl -T
use strict;
use warnings;
use CGI;
my $q = CGI->new;

my($pfiles, $file) = $q->param('file') =~ m/(.*\/)(.*)$/;
if ($file) {
open(DWFILE, '<', "./$pfiles/$file") or return(0);
print $q->header(-type => 'application/x-download',
-attachment => "./$pfiles/$file",
'Content-length'=> -s "./$pfiles/$file");
binmode DWFILE;
print while <DWFILE>;
close (DWFILE);

}


 
So, the file is named "test 1.txt" on the server, Perl shows its name as "test 1.txt", but your client software shows a dialog box showing "test_1.txt" and saves it to your disk as "test_1.txt"?

If that's all the case, it looks like the problem is in your client software (e-mail client or web browser?) and there's not much your Perl script can do about it.

Some programs automatically convert certain symbols in files downloaded off the web into more neutral things so as not to mess with the file system. For instance if an Internet server gives you a file to download named " test 1.txt" (with a space at the beginning of the file name), and your DOS-based (all Windows systems) filesystem saved it to disk, you'd wind up with a headache because the file would cause so many problems because of that leading space: it couldn't be opened, deleted, copied, moved, renamed, without using the command prompt and catching it in a wildcard statement, like "del *.*".

So try some different client software and see if it does the same thing.

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
If you mean the dialog box in a web browser, that should not change a space to an underscore. I suspect one of your perl scripts is changing the space to an underscore.

On the other hand, I wouldn't use that script to downlaod a file. It looks like the user could substitute the directory/name of the file to download and your script will blindly accept it because the regexp is not well written and there seems to be no other checks to make sure the user isn't trying something unusual.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Hi Guys,

I found the source of the problem, I don't experience this issue with Onternet Explorer 6 but I experience it with IE7.

Here is the solution to fix this issue.


Thanks for your help,
 
Well, there you go, its a bug in IE7, what a surprise.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Hi Kevin,

I tried this hotfix suggested by Microsoft on my XP SP3, but it does not work.

I found another link where they explain this issue and they ask to :
"To resolve this problem, do not use "Content-Disposition: Attachment; filename=" HTTP header."


Have you any alternative to "Content-Disposition: Attachment; filename=" ?

Thanks,

Imad
 
I don't know.


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top