Jump to content


Photo

using 'Content-Disposition: filename=' with files with spaces


  • Please log in to reply
7 replies to this topic

#1 Detail

Detail

    King Detail

  • Hosted
  • 7,767 posts
  • Location:Dayonic
  • Projects:Dayvi.com
  •  Blu Spy

Posted 25 January 2006 - 04:53 PM

When people download from AV, they code i use is:
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
echo(file_get_contents("uploads/$filename"));
If the filename has a space in it, the first part gets used.

Example:
File1 = spoon and knife.zip = spoon
File2 = spoonandknife.zip = spoonandknife.zip

What didly bits " ' ’ ` do i use to make use the full name?

#2 Guest_ImmoMan_*

Guest_ImmoMan_*
  • Guests

Posted 25 January 2006 - 05:21 PM

You should urlencode() the name before you print it. Spaces and a lot of other characters aren't allowed in URLs, they should be replaced by codes such as %20 for the space.

#3 Detail

Detail

    King Detail

  • Hosted
  • 7,767 posts
  • Location:Dayonic
  • Projects:Dayvi.com
  •  Blu Spy

Posted 25 January 2006 - 05:31 PM

I tryed:
$filename = urlencode($filename);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
echo(file_get_contents("uploads/$filename"));
and the out put was:
File1 = spoon and knife.zip = spoon+and+knife.zip
The file "spoon+and+knife.zip" dose not exist, so that did not work.


I just tryed
$filename = str_replace(" ", "%20", $filename);
and it came out as:
File1 = spoon and knife.zip = spoon%20and%20knife.zip
The file "spoon%20and%20knife.zip" dose not exist, so that did not work either.


Any other ideas?

#4 Guest_DarkUnminded_*

Guest_DarkUnminded_*
  • Guests

Posted 08 May 2008 - 04:12 AM

I hope you've already solved the problem...
I think the code should be something like:

[codebox]$filename_enc = urlencode($filename);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename_enc");
echo(file_get_contents("uploads/$filename"));[/codebox]

I hope it works. :p

#5 Bart

Bart

  • Network Admins
  • 8,524 posts
  • Location:The Netherlands
  • Division:Revora
  • Job:Network Leader

Posted 08 May 2008 - 09:41 PM

What's up with all the guest-necromancing lately
bartvh | Join me, make your signature small!
Einstein: "We can’t solve problems by using the same kind of thinking we used when we created them."

#6 Guest_eFeXi_*

Guest_eFeXi_*
  • Guests

Posted 10 July 2008 - 07:04 AM

I hope you've already solved the problem...
I think the code should be something like:

$filename_enc = urlencode($filename);header("Content-Type: application/octet-stream");header("Content-Disposition: attachment; filename=$filename_enc");echo(file_get_contents("uploads/$filename"));

I hope it works. :p


No, this does not work... but...

//Select the Browserfunction detect_browser($var){	if(eregi("(msie) ([0-9]{1,2}.[0-9]{1,3})", $var)){		$c = "ie"; 	}else{		$c = "nn"; 	}	return $c;}Header("Content-Description: File Transfer");if(detect_browser($HTTP_USER_AGENT) == "ie"){	Header("Content-type: application/force-download");}else{	Header("Content-Type: application/octet-stream");}//The only thing that is needed is "" which specifies that it is a complete sentenceHeader('Content-Disposition: attachment; filename="'.$filename'"');$n1= fopen($filename, 'r');while (!feof($n1)){	echo fgets($n1, 512);}fclose($n1);

It works, I have checked :)

thanks anyway, You helps me fix it :p

#7 Guest_Julio Montoya_*

Guest_Julio Montoya_*
  • Guests

Posted 03 September 2008 - 05:02 PM

I hope you've already solved the problem...
I think the code should be something like:

$filename_enc = urlencode($filename);header("Content-Type: application/octet-stream");header("Content-Disposition: attachment; filename=$filename_enc");echo(file_get_contents("uploads/$filename"));

I hope it works. :D


No, this does not work... but...

//Select the Browserfunction detect_browser($var){	if(eregi("(msie) ([0-9]{1,2}.[0-9]{1,3})", $var)){		$c = "ie"; 	}else{		$c = "nn"; 	}	return $c;}Header("Content-Description: File Transfer");if(detect_browser($HTTP_USER_AGENT) == "ie"){	Header("Content-type: application/force-download");}else{	Header("Content-Type: application/octet-stream");}//The only thing that is needed is "" which specifies that it is a complete sentenceHeader('Content-Disposition: attachment; filename="'.$filename'"');$n1= fopen($filename, 'r');while (!feof($n1)){	echo fgets($n1, 512);}fclose($n1);

It works, I have checked :thumbsupdrool:

thanks anyway, You helps me fix it :D




There was an error here (one dot was missing)

Header('Content-Disposition: attachment; filename="'.$filename.'"');

now it works.
Thanks

#8 Guest_Francis_*

Guest_Francis_*
  • Guests

Posted 06 February 2012 - 06:33 PM

Try wrapping the filename in double quotes.
header("Content-Disposition: attachment; filename=\"$filename\"");





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users