Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the mime type of a file after using file_get_contents from a remote server
    text
    copied!<p>i'm reading a file from php from Alfresco and then outputting it to the browser. The only ptoblem is the mimetype or the extension of the file. This is the code i'm using:</p> <pre><code>&lt;?php ob_start(); //require_once("libs/FirePHPCore/fb.php"); require_once("libs/AlfrescoConnect.php"); $nomeFile = rawurldecode($_GET['nomeFile']); $urlDownload = $_GET['urlDownload']; $fileDownloadUrl = AlfrescoConnect::$serverPath. $urlDownload . "&amp;attach=true&amp;alf_ticket=".AlfrescoConnect::getTiket(); fb($fileDownloadUrl); $cnt = file_get_contents($fileDownloadUrl); header("Content-type: Application/octet-stream"); header('Cache-Control: must-revalidate'); header('Content-disposition: attachment; filename=' .$nomeFile); echo($cnt); exit(); echo("Impossibile trovare il file"); </code></pre> <p>I receive the name of the file from the get becausa i don't know how to get the name from alfresco, but i have to guess the mimetype somehow. if i "echo" $cnt in the firsat caracters there are references to the fact that it is a PDF (for example on screen i see "%PDF-1.3 %âãÏÓ 2 0 obj &lt;&lt; /Length 3 0 R /Filter /CCITTFaxDecode /DecodeParms &lt;&lt; /K 0 /Columns 2480 /Rows 3508 >> /Type /XObject /Subtype /Image /Width 2480 /Height 3508 /BitsPerComponent 1 /ColorSpace /DeviceGray >> stream" so there must be a way to get the mime_tipe from it with a function.</p> <p>Any help is apprecieted!</p> <p>Edit. If anyone is intereste here is a class that you can use to get the extension from the mime-type. <a href="http://www.ustrem.org/en/articles/mime-type-by-extension-en/" rel="nofollow">http://www.ustrem.org/en/articles/mime-type-by-extension-en/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload