Setting Content_Type

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

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
Extension Customisations
Extension Customisations
Posts: 4133
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Setting Content_Type

Post by kasimi »

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

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
Extension Customisations
Extension Customisations
Posts: 4133
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Setting Content_Type

Post by kasimi »

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

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
Post Reply

Return to “Extension Writers Discussion”