title: Getting mime type of zipped files
body: <p>Getting the mime type of an uploaded file is easy enough:</p>
  
  <pre><code>echo mime_content_type($fileatt['tmp_name']);
  </code></pre>
  
  <p>However, I also want to check the mime-type of files which are included in a zipped file.  After unzipping my files (looping through the files in the zip and where <code>i</code> is the current file), I've tried:</p>
  
  <pre><code>$info = pathinfo($zip-&gt;getNameIndex($i));
  echo mime_content_type($info['dirname'] . "\\" . $info['basename']);
  </code></pre>
  
  <p>which gives the error: Warning: mime_content_type() [function.mime-content-type]: File or path not found '.\foo.pdf' in <code>C:\Users\&lt;user&gt;\&lt;website&gt;\validation.php</code> on line 56</p>
  
  <p>I realised that the <code>dirname</code> for a zipped file is relative to the zip file, not the absolute path, so I tried:</p>
  
  <pre><code>$a = pathinfo($fileatt['tmp_name']);
  $b = $a['dirname'] . "\\" . $info['basename'];
  echo mime_content_type($b);
  </code></pre>
  
  <p>which gives the error: Warning: mime_content_type() [function.mime-content-type]: File or path not found 'C:\xampp\tmp\foo.pdf' in <code>C:\Users\&lt;user&gt;\&lt;website&gt;\validation.php</code> on line 56</p>
  
  <p>Can anyone cast any light on the path of the file? (I suspect the answer might be the same as the comment on <a href="https://stackoverflow.com/questions/3536891/getting-image-height-and-width-from-zipped-files">getting image height and width from zipped files</a>, but are there any alternative methods?)</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Thanks to Baba, the following does work:</p>
  
  <pre><code>$fp = fopen('zip://C:\Users\&lt;user&gt;\&lt;website&gt;\test.zip#foo.jpg', "r");
  </code></pre>
  
  <p>(n.b. I can only get this to work when I give the full route of the zip file, not a tmp file as would be the case when a file is uploaded via a form).  However, trying to get the mime-type: <code>echo mime_content_type($fp);</code> generates the error: </p>
  
  <pre><code>Warning: mime_content_type() [function.mime-content-type]: stream does not support seeking in C:\Users\&lt;user&gt;\&lt;website&gt;\includes\validation.php on line 70
  </code></pre>
  
  <p>This happens regardless of the file type (i.e. the problem stated in the only comment on <a href="http://php.net/manual/en/ziparchive.getstream.php" rel="nofollow noreferrer">http://php.net/manual/en/ziparchive.getstream.php</a> doesn't seem to affect me).  </p>
  
  <p>Incidentally, this is also the same error I get when I try a different method: <code>$fp = $zip-&gt;getStream('foo.jpg');</code></p>
  
  <p>I know that there are several other 'stream not supported' questions on SO, but I couldn't work out how they related to my problem, and I was hoping that since this method has been specifically suggested someone might have a good answer...</p>
  
  <p>(p.s. I'm not using the <code>finfo_*</code> functions as my host currently refuses to install PHP v5.3).</p>