Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2015, 11:32 PM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default attachment.php header problem

This isn't for a modification. This is a problem I'm having with the stock VB 3.8.7 code.

I have attachments stored in the file system and I'm not using the lightbox feature. When a user clicks on a photo it opens by itself. However, if the user tries to save the photo, the filename is always "attachment.php" and not the actual file name.

This has been a problem in Internet Explorer for quite a while. The only workaround I knew of was to view the forum in "compatibility" mode in IE.

Now this has also become a problem in Firefox 39. Previous versions of Firefox didn't have this issue. When you tried to save a photo in Firefox 38, the correct file name was displayed in the "Save As" dialog box.

I believe this is the part of attachment.php that is causing the problem:
Code:
// Opera and IE have not a clue about this, mozilla puts on incorrect extensions.
if (is_browser('mozilla'))
{
	$filename = "filename*=" . $filename_charset . "''" . rawurlencode($filename);
	//$filename = "filename==?$stylevar[charset]?B?" . base64_encode($filename) . "?=";
}
else
{
	// other browsers seem to want names in UTF-8
	if ($filename_charset != 'utf-8' AND function_exists('iconv'))
	{
		$filename_conv = iconv($filename_charset, 'UTF-8//IGNORE', $filename);
		if ($filename_conv !== false)
		{
			$filename = $filename_conv;
		}
	}

	if (is_browser('opera') OR is_browser('konqueror') OR is_browser('safari'))
	{
		// Opera / Konqueror does not support encoded file names
		$filename = 'filename="' . str_replace('"', '', $filename) . '"';
	}
	else
	{
		// encode the filename to stay within spec
		$filename = 'filename="' . rawurlencode($filename) . '"';
	}
}

if (in_array($extension, array('jpg', 'jpe', 'jpeg', 'gif', 'png')))
{
	header("Content-disposition: inline; $filename");
	header('Content-transfer-encoding: binary');
}
else
{
	// force files to be downloaded because of a possible XSS issue in IE
	header("Content-disposition: attachment; $filename");
}
I've tried changing the Content-disposition: by changing the $filename variable and have found combinations that work in IE so that the correct filename is displayed in the "Save As" box instead of attachment.php.

I haven't found any fix that will make this code work correctly with Firefox 39.

Any ideas?

All help is appreciated.

Thanks,
James
Reply With Quote
  #2  
Old 07-15-2015, 01:50 AM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can see this problem right here on vbulletin.org

Just click on on any image attachment that was uploaded here and then try to save the attachment. Rather than seeing the image's actual file name, you'll get "attachment.php" as the file name in Internet Explorer (unless you have already set your browser to view vbulletin.org in "compatibility" mode) or while using Firefox 39. Earlier versions of Firefox (38 and below) work as you would expect and you see the attachment's real file name in the "Save As" dialog box.

This is an annoying problem for a forum with lots of image attachments that people want to save to their local computers, so I hope someone can share some insight on how to fix this.

Thanks for your help,
James
Reply With Quote
  #3  
Old 08-13-2015, 01:03 PM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Does anyone have any ideas or clues how to fix this issue?

It's bizarre. In Firefox 39, if you open a photo attachment and right-click over the image and choose "Save Image as..." you get attachment.php as the file name. This is the wrong/unexpected behavior.

In Firefox 39, if you open a photo attachment and right-click outside the image area (not directly over the photo) and choose "Save Page As..." you get the correct file name and extension.

This is just backward. You would think the page might be called attachment.php since that's the script serving the image, but the actual image should save with the correct file name.

It really doesn't matter is it's a bug in Firefox or a bug in vBulletin, either way I still need to find a work around.

Thanks for any help or suggestions.
Reply With Quote
  #4  
Old 08-13-2015, 02:52 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I just tried it with Firefox 39 and you are correct. However, I'm not sure what the fix for it is.
Reply With Quote
  #5  
Old 08-13-2015, 04:37 PM
Stratis's Avatar
Stratis Stratis is offline
 
Join Date: Jan 2010
Posts: 738
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<a href="https://vborg.vbsupport.ru/showthread.php?t=318860" target="_blank">https://vborg.vbsupport.ru/showthread.php?t=318860</a>
Same problem, I had it with IE11, Any way all problems are fixed with vb4.2.2 - 3
But for me for many reasons I will don't make the update yet.

I think that fix is with the php version
Reply With Quote
  #6  
Old 08-13-2015, 05:26 PM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
I just tried it with Firefox 39 and you are correct. However, I'm not sure what the fix for it is.
Lynne,
Can you do me a favor and confirm that this isn't a problem with vB4 and/or vB5 when browsing with Firefox 39?

Quote:
Originally Posted by Stratis View Post
https://vborg.vbsupport.ru/showthread.php?t=318860
Same problem, I had it with IE11, Any way all problems are fixed with vb4.2.2 - 3
But for me for many reasons I will don't make the update yet.

I think that fix is with the php version
Thanks for the tip Stratis. I'll try to take a look at what is different in the code in VB4.
Reply With Quote
  #7  
Old 08-13-2015, 06:45 PM
TheLastSuperman's Avatar
TheLastSuperman TheLastSuperman is offline
Senior Member
 
Join Date: Sep 2008
Location: North Carolina
Posts: 5,844
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Firefox 40 here but I adjusted my about:config and have done many warranty voiding things (I can run plugins and themes not marked as compatible and other novel things woohoo) so I can't even begin to offer suggestions other than this one:

Seems this is a known issue in IE and certain sites (depending on how their server/php is setup but does not mean its wrong) see post #21 here - http://blenderartists.org/forum/show...p-files/page2&

Make sure to edit your settings in IE11;
> Menu > Tools > Compatability View settings > Add vbulletin.org to the list, should be fixed now .

Edit: No offense intended however most of you are actually searching for this info right? I typed in "attachments saving as .php files?" into Google and BAM there it was in the top three search results... I'm going to just go now .

Edit #2: Also so you know, if you ever visit a site and attempt to download an attachment/image or simply click on a link and it opens the save dialog box... it can be several things... PHP Version on said site has changed / recent .htaccess change / usually some type of configuation OR setup change recently made so if you're ever working on your site then it acts a fool simply revert the recent change made and viola, should return to normal.
Reply With Quote
  #8  
Old 08-13-2015, 09:34 PM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the info TheLastSuperman.

However, in this case it is a software issue not a server issue. I'm aware of the compatibility mode work around, but that isn't a very elegant solution. I don't like idea of telling thousands of members to change their browser settings because we can't get our code working right. I want to fix things properly on our end and that means dealing with all the quirks in different browsers.

I don't have a fix for Firefox 39 yet, but this simple change seems to make the file names appear correctly in Internet Explorer without having to enable compatibility mode.

Look for this in attachment.php:
Code:
// Opera and IE have not a clue about this, mozilla puts on incorrect extensions.
if (is_browser('mozilla'))
{
	$filename = "filename*=" . $filename_charset . "''" . rawurlencode($filename);
	//$filename = "filename==?$stylevar[charset]?B?" . base64_encode($filename) . "?=";
}
And change it to this:
Code:
// Opera and IE have not a clue about this, mozilla puts on incorrect extensions.
if (is_browser('mozilla'))
{
	//$filename = "filename*=" . $filename_charset . "''" . rawurlencode($filename);
	//$filename = "filename==?$stylevar[charset]?B?" . base64_encode($filename) . "?=";
	$filename = 'filename="' . str_replace('"', '', $filename) . '"';    //This works in IE
}
I'm only running this on my test server so far and I'm not calling this a permanent solution until I find out (and fix) why Firefox stopped handling file names as expected.

Thanks,
James
Reply With Quote
Благодарность от:
Stratis
  #9  
Old 08-17-2015, 03:12 PM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

As far as Firefox is concerned, it appears that this was a bug in Firefox 39..
I just upgraded to Firefox 40.0.2 and the issue no longer exists.

I'll try testing my IE fix on a live forum next.

Thanks,
James
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:41 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04700 seconds
  • Memory Usage 2,255KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (1)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete