Resources

My Agape try

Your Agape try


Support Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




Attachments and IE7

UserPost

9:44 am
December 16, 2008


YikYak

Member

posts 70

1

Hi Kevin,

Having a problem with attachments, using RC4-b, with Firefox all is well, but with IE7 a link to a pdf file just returns a blank page. If I turn of RS altogether, then the pdf is served in IE7.

Thanks

YikYak

8:59 am
December 18, 2008


Kevin

Admin

posts 2386

2

What does IE7 do if you right-click on the link and ask for a file save?

Can you try these 3 experiments on the agp_return_file function in plugins/role-scoper/agapetry_lib.php to help me diagnose this?

  • comment out or delete the entire if ( $is_apache ) block to disable server caching.
  • add the following code after the existing content-type line:

global $is_IE;

if ( $is_IE ) {

header('Content-disposition: attachment; filename=' . basename($file_path) );
}
  • replace the content-type line with this:

global $is_IE;

if ( $is_IE && ('application/pdf' == $type) ) {

header('Content-Type: application/x-msdownload');

} else {

header( “Content-Type: $type” );

}

9:23 am
December 18, 2008


YikYak

Member

posts 70

3

If I right click and "save target as", then I get a pop-up with:

Internet Explorer cannot download file from server .

The file could not be written to the cache.

Working on the other tips.

2:06 pm
December 18, 2008


YikYak

Member

posts 70

4

Hi Kevin,

Working on the first suggestion, file actually in "lib" subdirectory, deleted this (RS1.0.0RC4b):

    if ( $is_apache ) {
        // If web server is apache, check HTTP If-Modified-Since header before sending content
        $ar = apache_request_headers();
        if ( ! empty($ar['If-Modified-Since']) && ( strtotime($ar['If-Modified-Since']) >= $file_time ) ) {
            // 304: "Browser, your cached version of image is OK; we're not sending anything new to you"
            header( 'Last-Modified: '.gmdate('D, d M Y H:i:s', $file_time).' GMT', true, 304 );
            return;
        }
    }

I de-activated, then re-activated RS. I installed Lester Chan's wp-serverinfo (or similar) to verify I'm on Apache 2.2.3. 

I made a test post with 3 sorts of files in my uploads directory, just for some variation, and left clicked on them all, with the modified file as above.

A .gif is served normally and displays in IE

A .pdf file, no apparent change, nothing happens with left click in IE. Well a little blue status bar at the foot of IE would indicate some downlaod type activity, but no outcome from that. I tried other pdf elsewhere on the server, and that works, and also fine without RS active.

A .doc file, IE invites me to "open" or "save" or "cancel". If I "save" then I get a pop-up telling me:

"Internet Explorer cannot download [file] from [server]. Internet Explorer was not able to open this internet site. The requested site is either unavailable or cannot be found. Please try again later."

If I "open" then I seem to get invited for my https:// credentials again, and back to page with downloads on.

When I right click, save target as…I get the file cannot be written to the cache errors. I also get this with the .gif (served on left click).

I'll re-insert this deleted "if" code block, and try the next test…perhaps another day. Other work to do :(

I am on a secure server (https://) if that makes any difference? Firefox behaves fine with this modified code.


4:16 pm
December 18, 2008


Kevin

Admin

posts 2386

5

YikYak said:

I'll re-insert this deleted “if” code block, and try the next test…perhaps another day. Other work to do :(

I am on a secure server (https://) if that makes any difference? Firefox behaves fine with this modified code.


Better yet, try replacing the whole function with this:

function agp_return_file( $file_path, $mime_type ) {
	$file_time = filemtime($file_path);

	// server caching code from Private Files plugin by James Low (http://jameslow.com/2008/01/28/private-files/),
	global $is_apache;
	if ( $is_apache ) {
		// If web server is apache, check HTTP If-Modified-Since header before sending content
		$ar = apache_request_headers();
		if ( ! empty($ar['If-Modified-Since']) && ( strtotime($ar['If-Modified-Since']) >= $file_time ) ) {
			// 304: "Browser, your cached version of image is OK; we're not sending anything new to you"
			header( 'Last-Modified: '.gmdate('D, d M Y H:i:s', $file_time).' GMT', true, 304 );
			return;
		}
	}

	// outputing Last-Modified header
	header( 'Last-Modified: '.gmdate('D, d M Y H:i:s', $file_time).' GMT', true, 200 );

	if ( ( false !== strpos( $mime_type, 'image/' ) ) 
|| ( false !== strpos( $mime_type, 'video/' ) ) || ( false !== strpos( $mime_type, 'audio/' ) ) ) {
		header('Cache-Control: must-revalidate');
		header( "Content-Type: $mime_type" );
	} else {
		global $is_IE;
		if ( $is_IE ) {
			// Thanks to Eirik Hoem - 
			// http://eirikhoem.wordpress.com/2007/06/15/generated-pdfs-over-https-with-internet-explorer/
			// for the tip on header requirements for IE7 https download
			header('Cache-Control: maxage=3600');
			header('Pragma: public');

			header("Content-Description: File Transfer");
			header("Content-Transfer-Encoding: binary");
			header('Content-Type: application/x-msdownload');
			header('Content-Disposition: attachment; filename="' . basename($file_path) . '"');
		} else {
			header('Cache-Control: must-revalidate');
			header( "Content-Type: $mime_type" );
		}
	}

	header( 'Content-Length: ' . filesize($file_path) );

	ob_clean();
	flush();
	readfile($file_path);
}

The https:// mention was the clue I needed.

I'm e-mailing you a copy of the revised file to make your next trial easier.

5:10 pm
December 18, 2008


YikYak

Member

posts 70

6

That worked! Thanks. Can now download from IE. But in testing, I found another problem, which may just be me not understanding things properly.

I have a number of users, who are allowed to read (and write) only in certain categories. This seems to work fine. In testing this download problem, I write a random post with some random attachments, and put it in a general category where it could be seen by all my registered users. But to hide it from them (it did not matter this did not work) I attempted to define read only from the post edit page. (The "post roles" options page seems to think this is set….)

In edit post:

I checked the box to "restrict for post - only selected groups/users are readers" and then added one of each, a user and a group, both admins. But a test user, who does not fall into this set, can see the post. What might I be doing wrong? (I have never used this facility to really narrow the readership before).

10:18 pm
December 18, 2008


Kevin

Admin

posts 2386

7

My guess is that your test user has a Contributor, Author or Editor role which is not restricted.  In that case, they would still be able to read the post. 

To block a user from reading a particular post, you have to restrict all the roles they have which would qualify for the requested read operation. 

The user color highlighting in the Post/Page Edit form indicates this (”has via other role”. “has via other scope”).  I did notice, though that said highlighting is currently not working for users who have a Readers role implicitly via Contributor role assignment.  This too shall be fixed.

Under the default config, a WordPress Contributor essentially has the Post Contributor and Post Reader role, either of which qualify for a read request.  Note that Contributor can't read private posts, though.

A WordPress Editor essentially has the Post Editor, Post Author, Post Contributor, Private Post Reader and Post Reader role.

I need to expand the documentation on this topic.


And boy do I ever need to come up with a different code snippet solution.


2:47 am
December 19, 2008


YikYak

Member

posts 70

8

that's nailed it Smile


About the Agapetry forum

Currently Online:

sethstevenson

14 Guests

Maximum Online: 150

Forums:

Groups: 2

Forums: 7

Topics: 1184

Posts: 5379

Members:

There are 1176 members

There are 1 guests


Kevin has made 2386 posts

Top Posters:

metal450 - 152

Ragnar - 105

YikYak - 70

whiteorb - 44

Daisy - 35

Administrator: Kevin | Moderators: Kevin