Delivering Content-Type when known, but not by file ext

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Delivering Content-Type when known, but not by file ext

Postby shortmort37 » 08. August 2016 15:38

I run a phpBB board, where attachments are uploaded stored without extension - however, the mime-type is stored in the database. When delivering the attachment for display, I want to be able to specify Content-Type header based on the type, which cannot be derived from the stored filename. Here is a simple example: http://www.59plymouth.net/content-type/test.html

If you click on the left icon where the extension is specified, the video plays. If you click on the right icon sans extension, but where "type" is specified, it downloads the video because the content-type is not known. How do I tell Apache, to deliver the appropriate content-type of "video/mp4" in this particular example? (I get the same behavior with XAMPP on my desktop, but my hosting site runs Apache under linux.)

Here is the code:

Code: Select all
<html>
<body>
<a href="./media/2.mp4"><img src="./media/2_thumb.jpg"/></a>
<a href="./media/2" type="video/mp4"><img src="./media/2_thumb.jpg"/></a>
</body>
</html>


Thanks
Dan
shortmort37
 
Posts: 8
Joined: 08. February 2016 14:32
Operating System: Windows 8.1

Re: Delivering Content-Type when known, but not by file ext

Postby shortmort37 » 08. August 2016 15:59

Oh, and just to note - I can have mixed media, so it won't do to fix the Content-Type for all references on that page. I want to be able to click a hyperlink, and trigger the transmission of the appropriate Content-Type for the object referenced in that link.

Dan
shortmort37
 
Posts: 8
Joined: 08. February 2016 14:32
Operating System: Windows 8.1

Re: Delivering Content-Type when known, but not by file ext

Postby Nobbie » 09. August 2016 14:10

How do you eveluate the Content-Type from the file, if it cannot be derived from the name? How should Apache "know" the Content-Type (as you see, there is no "type" attribute in Links or URLs)? Assume, i upload a file with the name xyz. What is the Conten-Type of that file?

After you know the Content-Type (but i still have no idea how to eveluate from the filename only), you might use a PHP Script to set the appropriate Content-Type for the download (a small PHP Script that triggers the download for all files). But this is step two - first of all i have to know, how to evaluate the Content-Type?
Nobbie
 
Posts: 8770
Joined: 09. March 2008 13:04

Re: Delivering Content-Type when known, but not by file ext

Postby shortmort37 » 09. August 2016 14:24

When the user clicks on the link in this anchor, the href gets passed to Apache - doesn't the type as well?

<a href="./media/2" type="video/mp4"><img src="./media/2_thumb.jpg"/></a>

What purpose does the endorsed attribute serve, if not to convey content type?

Dan
shortmort37
 
Posts: 8
Joined: 08. February 2016 14:32
Operating System: Windows 8.1

Re: Delivering Content-Type when known, but not by file ext

Postby Nobbie » 09. August 2016 15:27

shortmort37 wrote:What purpose does the endorsed attribute serve, if not to convey content type


From http://www.w3schools.com/tags/att_a_type.asp

Note: This attribute is purely advisory.


And (most important) Apache does not "understand" HTML, this attribute is not passed to Apache in any way. The browser generates a HTTP Request from an URL if someone clicks on it, but this request does not contain any Content-Type specification. The type-Attribute might be interpreted by JavaScript or similar (i.e. by the browser), but Apache does not know about that. Its still unsolved, how do you tell Apache which Content-Type does "xyz" have?

shortmort37 wrote:When the user clicks on the link in this anchor, the href gets passed to Apache - doesn't the type as well?


No and no. Href is NOT(!) passed to Apache, instead the Browser parses the contents of href and sends an HTTP request to the server. This request does not contain any type (HTTP does not know any type at this point of HTTP protocoll). Content-Type is a part of the HTTP Header when Apache responses to the request. But it is not part of the request send by the browser.
Nobbie
 
Posts: 8770
Joined: 09. March 2008 13:04

Re: Delivering Content-Type when known, but not by file ext

Postby shortmort37 » 09. August 2016 15:36

Nobbie wrote:... you might use a PHP Script to set the appropriate Content-Type for the download (a small PHP Script that triggers the download for all files). But this is step two - first of all i have to know, how to evaluate the Content-Type?


Ah.

Server-side, I do know the Content-Type - it's recorded in the phpBB database, along with the filename.

If I retrieve the Content-Type for the object that is requested, how would I set it in the stream with PHP?
shortmort37
 
Posts: 8
Joined: 08. February 2016 14:32
Operating System: Windows 8.1

Re: Delivering Content-Type when known, but not by file ext

Postby Altrea » 09. August 2016 15:44

We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8293
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: DrSeussFreak and 55 guests