Setting Content_Type

Discussion forum for Extension Writers regarding Extension Development.
User avatar
shortmort37
Registered User
Posts: 658
Joined: Sat Aug 26, 2006 8:40 pm
Location: Upper Darby, PA, USA
Name: Dan Morton

Re: Setting Content_Type

Post by shortmort37 »

Same error (just a line further down with the "use" added).
Catchable fatal error: Argument 1 passed to Symfony\Component\HttpFoundation\BinaryFileResponse::prepare() must be an instance of Symfony\Component\HttpFoundation\Request, instance of phpbb\request\request given, called in /home/sportf5/public_html/59test/includes/functions_download.php on line 143 and defined in /home/sportf5/public_html/59test/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/BinaryFileResponse.php on line 169
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany

Re: Setting Content_Type

Post by kasimi »

Post the whole if ($category == ATTACHMENT_CATEGORY_HTML5 ...) block.
User avatar
shortmort37
Registered User
Posts: 658
Joined: Sat Aug 26, 2006 8:40 pm
Location: Upper Darby, PA, USA
Name: Dan Morton

Re: Setting Content_Type

Post by shortmort37 »

These are my mods - at the top,

Code: Select all

use Symfony\Component\HttpFoundation\BinaryFileResponse;
use phpbb\symfony_request;
Then:

Code: Select all

	if (!@file_exists($filename))
	{
		send_status_line(404, 'Not Found');
		trigger_error('ERROR_NO_ATTACHMENT');
	}
	// *** Adding HTML5 audio/video content!  Caveat Emptor
	if (($category == ATTACHMENT_CATEGORY_HTML5)
		&& ((strpos($attachment['mimetype'], 'video') !== 0)||(strpos($attachment['mimetype'], 'audio') !== 0)))
	{
		$response = new BinaryFileResponse($filename);
		$response->headers->set('Content-Type', 'video/mp4');
		global $request;
		$response->prepare($request); 
		$response->send();
		exit;
	}
	// Correct the mime type - we force application/octetstream for all files, except images
	// Please do not change this, it is a security precaution
	if (($category != ATTACHMENT_CATEGORY_IMAGE || strpos($attachment['mimetype'], 'image') !== 0))
...
I've forced the Content-Type here to be video, but of course if I get it to work I would set it to audio/video as appropriate.
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany

Re: Setting Content_Type

Post by kasimi »

You missed the last line in this post. :)
User avatar
shortmort37
Registered User
Posts: 658
Joined: Sat Aug 26, 2006 8:40 pm
Location: Upper Darby, PA, USA
Name: Dan Morton

Re: Setting Content_Type

Post by shortmort37 »

Indeed I did! It reminds me of a joke:

Q: What does a dyslexic agnostic insomniac do?
A: He lies awake all night, and wonders if there really is a dog.

(!)

Hey, it works!! Not only that...




It works on my iPad, which was the whole objective of this little exercise!

Many, many thanks. I will make revision to add mp3 capability as well. This is awesome!

Dan
playagiron
Registered User
Posts: 95
Joined: Tue Dec 08, 2009 2:18 pm

Re: Setting Content_Type

Post by playagiron »

Hi,

I know it is an old topic.

But struggling with the same issues of not playing MP3 files in the latest 3.3.11 version.

Bit hard to follow how to finally achieve the right "audio/mpeg" mimetype for mp3 attachments.

Anyone still following who could give the whole set of mods required?

Thanks a dozen!
Johannes
User avatar
Mick
Support Team Member
Support Team Member
Posts: 26710
Joined: Fri Aug 29, 2008 9:49 am

Re: Setting Content_Type

Post by Mick »

phpBB no longer uses or recommends mods as extensions have been in use since 3.1. I suggest you make an extension request, you can link back to this topic if you wish.

Are you saying if you attach an mp3 file you can’t play it? I’ve just tried it and it works fine:

IMG_0424.jpeg

Are you sure you have the attachment settings set correctly?
You do not have the required permissions to view the files attached to this post.
  • "The more connected we get the more alone we become" - Kyle Broflovski©
  • "The good news is hell is just the product of a morbid human imagination.
    The bad news is, whatever humans can imagine, they can usually create.
    " - Harmony Cobel©
🇬🇧
playagiron
Registered User
Posts: 95
Joined: Tue Dec 08, 2009 2:18 pm

Re: Setting Content_Type

Post by playagiron »

Hi thanks! yes I see the differences from MODs to EXT 8just migrated my board).

It DOES work on PC, linux whatnot. Just NOT on iOS devices, either browser,
as the emimetype for non-images is always octet-stream. And not audio/mpeg.
hard coded files work but the download PHP links get this general mimetype which Apple seems not to recognize as playable html5 files.
playagiron
Registered User
Posts: 95
Joined: Tue Dec 08, 2009 2:18 pm

Re: Setting Content_Type

Post by playagiron »

This part in the code includes/functions_download.php

Code: Select all

	// Correct the mime type - we force application/octetstream for all files, except images
	// Please do not change this, it is a security precaution
	if ($category != ATTACHMENT_CATEGORY_IMAGE || strpos($attachment['mimetype'], 'image') !== 0)
	{
		$attachment['mimetype'] = (strpos(strtolower($user->browser), 'msie') !== false || strpos(strtolower($user->browser), 'opera') !== false) ? 'application/octetstream' : 'application/octet-stream';
	}
	
seems to set the mime-type. I tried also adding an exception for audio files to test if it works but seems to not change anything. Any other place I need to change to test passing the mime type from the SQL attachment tables instead of octetstream?
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28814
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier

Re: Setting Content_Type

Post by Paul »

This forum is for extensions writers support. If you have a issue with phpBB features itself, you should post in the support forum and provide the SRT so people can give proper support.
User avatar
Mick
Support Team Member
Support Team Member
Posts: 26710
Joined: Fri Aug 29, 2008 9:49 am

Re: Setting Content_Type

Post by Mick »

playagiron wrote: Mon May 06, 2024 10:13 pmIt DOES work on PC, linux whatnot. Just NOT on iOS devices
The example I posted was on a MacBook with Safari and FF so I’m not sure what the issue is with iOS, I tried iOS as well and it wanted to download the file which I did and it played ok.

This may be useful https://discussions.apple.com/thread/25 ... ortBy=best
  • "The more connected we get the more alone we become" - Kyle Broflovski©
  • "The good news is hell is just the product of a morbid human imagination.
    The bad news is, whatever humans can imagine, they can usually create.
    " - Harmony Cobel©
🇬🇧
playagiron
Registered User
Posts: 95
Joined: Tue Dec 08, 2009 2:18 pm

Re: Setting Content_Type

Post by playagiron »

Paul wrote: Tue May 07, 2024 9:20 am This forum is for extensions writers support. If you have a issue with phpBB features itself, you should post in the support forum and provide the SRT so people can give proper support.
Hi Paul,

yes I noted. And had in fact created a SRT post here: viewtopic.php?p=16011094#p16011094
But was forwarded to this topic, which is not fully complete at least it seems (in the sense I cannot replicate all the modifications required to make it work on my board.
In case someone has another idea or summary of all the changes that are required to pass the right mime type for files here mp3s would be much appreciated! Thanks!

Return to “Extension Writers Discussion”