Correct headers for php outputting an image to load in Flash

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
jggretton
Forum Newbie
Posts: 8
Joined: Fri Sep 15, 2006 7:14 am

Correct headers for php outputting an image to load in Flash

Post by jggretton »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Sorry, not the clearest of titles!

This is my first post on DevNetwork, looks like a great community you've got here!

Anyway, onto my problem:

I have been outputting jpg files through a php script using the following code:

Code: Select all

$file['file_size'] = filesize($local_file_name);
	$file['file_name'] = basename($local_file_name);
	$details = getimagesize($local_file_name);	
	$file['file_type'] = image_type_to_mime_type($details[2]);

	header("MIME-Version: 1.0");
	header( "Content-length: {$file['file_size']}" );
	header( "Content-type: {$file['file_type']}" );
	header( "Content-transfer-encoding: 8bit");
	header( "Content-disposition: inline; filename=\"{$file['file_name']}\"" );

	// read and output the file in chunks to bypass limiting settings in php.ini
	$local_handle = @fopen($local_file_name, 'rb');	
	while ( !feof($local_handle) ) {
		print fread($local_handle, 8192);
	}
	fclose($local_handle);

	//Note: the same problem occurs when using: "print file_get_contents($local_file_name);" instead.
In the browser this displays images perfectly – no problems what-so-ever. However I have been loading this image into Macromedia Flash… Flash displays the image flawlessly, however the next time I try to change url, internet explorer just goes to a blank page! After that, back and forward buttons all go to blank pages too! The user is screwed until they press refresh, then everything is fine again. (Doesn’t happen in Safari, FireFox or Opera, and never happens when directly loading an image file!)

Can anyone see any glaring errors with my headers or shed any light on this. My assumption is that Flash is still trying to communicate with the server about the image for some reason and the next request just kills everything?

Any ideas would be greatly appreciated,

Thanks,

James


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
jggretton
Forum Newbie
Posts: 8
Joined: Fri Sep 15, 2006 7:14 am

Post by jggretton »

Sorry feyd, will make sure my posts are a little prettier!

Does anyone have any suggestions as to why I might have been killing ie?

Thanks, James
Post Reply