Firefox screws up file name during download

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zixp
Forum Newbie
Posts: 1
Joined: Mon Feb 07, 2005 10:07 pm

Firefox screws up file name during download

Post by zixp »

Hi, I have a page that sends a file as an attachment. It woks just fine in IE, but in Firefox, all but the first word on the filename is cut off. I am using basename(), and I have tried to put quotes in the header call unsucessfully. I am not very familiar with headers. Below is the code used, any suggestions on how to fix this would be greatly appreciated.

//Send file via header
if (isset($fileandpath) && file_exists($fileandpath)) {
header("Content-type: application/octet-stream");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($fileandpath));
header("Content-disposition: attachment; filename=".basename($fileandpath));
readfile("$fileandpath");
} else {
echo "No file selected, or file doesn't exist";
echo "file request is failed for: ".$file."<br>";

}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

urlencode() should take care of it nicely, or one of the over conversions..
Post Reply