<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.exif.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.exif-read-data.php',
    1 => 'exif_read_data',
    2 => 'Reads the EXIF headers from an image file',
  ),
  'up' => 
  array (
    0 => 'ref.exif.php',
    1 => 'Exif Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.exif-imagetype.php',
    1 => 'exif_imagetype',
  ),
  'next' => 
  array (
    0 => 'function.exif-tagname.php',
    1 => 'exif_tagname',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/exif/functions/exif-read-data.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.exif-read-data" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">exif_read_data</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">exif_read_data</span> &mdash; <span class="dc-title">Reads the <abbr title="Exchangeable Image File ">EXIF</abbr> headers from an image file</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.exif-read-data-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>exif_read_data</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$file</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$required_sections</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$as_arrays</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$read_thumbnail</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span><br>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="simpara">
   <span class="function"><strong>exif_read_data()</strong></span> reads the
   <abbr title="Exchangeable Image File ">EXIF</abbr> headers from an image file. This way you can read meta data
   generated by digital cameras.
  </p>
  <p class="simpara">
   <abbr title="Exchangeable Image File ">EXIF</abbr> headers tend to be present in JPEG/TIFF images generated by digital
   cameras, but unfortunately each digital camera maker has a different
   idea of how to actually tag their images, so you can&#039;t always rely on
   a specific Exif header being present.
  </p>
  <p class="simpara">
   <code class="literal">Height</code> and <code class="literal">Width</code> are computed the
   same way <span class="function"><a href="function.getimagesize.php" class="function">getimagesize()</a></span> does so their values must not be
   part of any header returned.  Also, <code class="literal">html</code> is a
   height/width text string to be used inside normal <abbr title="Hyper Text Markup Language">HTML</abbr>.
  </p>
  <p class="simpara">
   When an Exif header contains a Copyright note, this itself can contain two
   values. As the solution is inconsistent in the Exif 2.10 standard, the
   <code class="literal">COMPUTED</code> section will return both entries
   <code class="literal">Copyright.Photographer</code> and
   <code class="literal">Copyright.Editor</code> while the <code class="literal">IFD0</code>
   sections contains the byte array with the NULL character that splits both
   entries. Or just the first entry if the datatype was wrong (normal behaviour
   of Exif). The <code class="literal">COMPUTED</code> will also contain the entry
   <code class="literal">Copyright</code> which is either the original copyright string,
   or a comma separated list of the photo and editor copyright.
  </p>
  <p class="simpara">
   The tag <code class="literal">UserComment</code> has the same problem as the Copyright
   tag. It can store two values.  First the encoding used, and second the value
   itself. If so the <code class="literal">IFD</code> section only contains the encoding
   or a byte array. The <code class="literal">COMPUTED</code> section will store both in
   the entries <code class="literal">UserCommentEncoding</code> and
   <code class="literal">UserComment</code>. The entry <code class="literal">UserComment</code>
   is available in both cases so it should be used in preference to the value
   in <code class="literal">IFD0</code> section.
  </p>
  <p class="simpara">
   <span class="function"><strong>exif_read_data()</strong></span> also validates EXIF data tags according
   to the EXIF specification (<a href="http://exif.org/Exif2-2.PDF" class="link external">&raquo;&nbsp;http://exif.org/Exif2-2.PDF</a>, page 20).
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.exif-read-data-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <dl>
   
    <dt><code class="parameter">file</code></dt>
    <dd>
     <span class="simpara">
      The location of the image file. This can either be a path to the file
      (stream wrappers are also supported as usual)
      or a stream <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>.
     </span>
    </dd>
   
   
    <dt><code class="parameter">required_sections</code></dt>
    <dd>
     <p class="para">
      Is a comma separated list of sections that need to be present in file
      to produce a result <span class="type"><a href="language.types.array.php" class="type array">array</a></span>.  If none of the requested
      sections could be found the return value is <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
      <table class="doctable informaltable">
       
        <tbody class="tbody">
         <tr>
          <td>FILE</td>
          <td>FileName, FileSize, FileDateTime, SectionsFound</td>
         </tr>

         <tr>
          <td>COMPUTED</td>
          <td>
           html, Width, Height, IsColor, and more if available.  Height and
           Width are computed the same way <span class="function"><a href="function.getimagesize.php" class="function">getimagesize()</a></span>
           does so their values must not be part of any header returned.
           Also, <code class="literal">html</code> is a height/width text string to be used inside normal
           <abbr title="Hyper Text Markup Language">HTML</abbr>.
          </td>
         </tr>

         <tr>
          <td>ANY_TAG</td>
          <td>Any information that has a Tag e.g. <code class="literal">IFD0</code>, <code class="literal">EXIF</code>, ...</td>
         </tr>

         <tr>
          <td>IFD0</td>
          <td>
           All tagged data of IFD0. In normal imagefiles this contains
           image size and so forth.
          </td>
         </tr>

         <tr>
          <td>THUMBNAIL</td>
          <td>
           A file is supposed to contain a thumbnail if it has a second <code class="literal">IFD</code>.
           All tagged information about the embedded thumbnail is stored in
           this section.
          </td>
         </tr>

         <tr>
          <td>COMMENT</td>
          <td>Comment headers of JPEG images.</td>
         </tr>

         <tr>
          <td>EXIF</td>
          <td>
           The EXIF section is a sub section of <code class="literal">IFD0</code>. It contains
           more detailed information about an image. Most of these entries
           are digital camera related.
          </td>
         </tr>

        </tbody>
       
      </table>

     </p>
    </dd>
   
   
    <dt><code class="parameter">as_arrays</code></dt>
     <dd>
     <span class="simpara">
      Specifies whether or not each section becomes an array. The
      <code class="parameter">required_sections</code> <code class="literal">COMPUTED</code>,
      <code class="literal">THUMBNAIL</code>, and <code class="literal">COMMENT</code>
      always become arrays as they may contain values whose names conflict
      with other sections.
     </span>
    </dd>
   
   
    <dt><code class="parameter">read_thumbnail</code></dt>
    <dd>
     <span class="simpara">
      When set to <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> the thumbnail itself is read.  Otherwise, only the
      tagged data is read.
     </span>
    </dd>
   
  </dl>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.exif-read-data-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="simpara">
   It returns an associative <span class="type"><a href="language.types.array.php" class="type array">array</a></span> where the array indexes are
   the header names and the array values are the values associated with
   those headers. If no data can be returned,
   <span class="function"><strong>exif_read_data()</strong></span> will return <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.exif-read-data-errors">
  <h3 class="title">Errori/Eccezioni</h3>
  <p class="simpara">
   Errors of level <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> and/or <strong><code><a href="errorfunc.constants.php#constant.e-notice">E_NOTICE</a></code></strong>
   may be raised for unsupported tags or other potential error conditions, but the
   function still tries to read all comprehensible information.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.exif-read-data-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versione</th>
      <th>Descrizione</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">required_sections</code> is nullable now.
      </td>
     </tr>

     <tr>
      <td>7.2.0</td>
      <td>
       The <code class="parameter">file</code> parameter now supports both local files
       and stream resources.
      </td>
     </tr>

     <tr>
      <td>7.2.0</td>
      <td>
       <p class="para">
        Support for the following EXIF formats were added:
        <ul class="simplelist">
         <li>Samsung</li>
         <li>DJI</li>
         <li>Panasonic</li>
         <li>Sony</li>
         <li>Pentax</li>
         <li>Minolta</li>
         <li>Sigma/Foveon</li>
         <li>AGFA</li>
         <li>Kyocera</li>
         <li>Ricoh</li>
         <li>Epson</li>
        </ul>
       </p>
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>

 <div class="refsect1 examples" id="refsect1-function.exif-read-data-examples">
  <h3 class="title">Esempi</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>exif_read_data()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"test1.jpg:&lt;br /&gt;\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$exif </span><span style="color: #007700">= </span><span style="color: #0000BB">exif_read_data</span><span style="color: #007700">(</span><span style="color: #DD0000">'tests/test1.jpg'</span><span style="color: #007700">, </span><span style="color: #DD0000">'IFD0'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$exif</span><span style="color: #007700">===</span><span style="color: #0000BB">false </span><span style="color: #007700">? </span><span style="color: #DD0000">"No header data found.&lt;br /&gt;\n" </span><span style="color: #007700">: </span><span style="color: #DD0000">"Image contains headers&lt;br /&gt;\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$exif </span><span style="color: #007700">= </span><span style="color: #0000BB">exif_read_data</span><span style="color: #007700">(</span><span style="color: #DD0000">'tests/test2.jpg'</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"test2.jpg:&lt;br /&gt;\n"</span><span style="color: #007700">;<br />foreach (</span><span style="color: #0000BB">$exif </span><span style="color: #007700">as </span><span style="color: #0000BB">$key </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$section</span><span style="color: #007700">) {<br />    foreach (</span><span style="color: #0000BB">$section </span><span style="color: #007700">as </span><span style="color: #0000BB">$name </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$val</span><span style="color: #007700">) {<br />        echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$key</span><span style="color: #DD0000">.</span><span style="color: #0000BB">$name</span><span style="color: #DD0000">: </span><span style="color: #0000BB">$val</span><span style="color: #DD0000">&lt;br /&gt;\n"</span><span style="color: #007700">;<br />    }<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>
    The first call fails because the image has no header information.
   </p></div>
   <div class="example-contents"><p>Il precedente esempio visualizzerà
qualcosa simile a:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">test1.jpg:
No header data found.
test2.jpg:
FILE.FileName: test2.jpg
FILE.FileDateTime: 1017666176
FILE.FileSize: 1240
FILE.FileType: 2
FILE.SectionsFound: ANY_TAG, IFD0, THUMBNAIL, COMMENT
COMPUTED.html: width=&quot;1&quot; height=&quot;1&quot;
COMPUTED.Height: 1
COMPUTED.Width: 1
COMPUTED.IsColor: 1
COMPUTED.ByteOrderMotorola: 1
COMPUTED.UserComment: Exif test image.
COMPUTED.UserCommentEncoding: ASCII
COMPUTED.Copyright: Photo (c) M.Boerger, Edited by M.Boerger.
COMPUTED.Copyright.Photographer: Photo (c) M.Boerger
COMPUTED.Copyright.Editor: Edited by M.Boerger.
IFD0.Copyright: Photo (c) M.Boerger
IFD0.UserComment: ASCII
THUMBNAIL.JPEGInterchangeFormat: 134
THUMBNAIL.JPEGInterchangeFormatLength: 523
COMMENT.0: Comment #1.
COMMENT.1: Comment #2.
COMMENT.2: Comment #3end
THUMBNAIL.JPEGInterchangeFormat: 134
THUMBNAIL.Thumbnail.Height: 1
THUMBNAIL.Thumbnail.Height: 1</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-2">
   <p><strong>Example #2 <span class="function"><strong>exif_read_data()</strong></span> with streams available as of PHP 7.2.0</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Open a the file, this should be in binary mode<br /></span><span style="color: #0000BB">$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'/path/to/image.jpg'</span><span style="color: #007700">, </span><span style="color: #DD0000">'rb'</span><span style="color: #007700">);<br /><br />if (!</span><span style="color: #0000BB">$fp</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">'Error: Unable to open image for reading'</span><span style="color: #007700">;<br />    exit;<br />}<br /><br /></span><span style="color: #FF8000">// Attempt to read the exif headers<br /></span><span style="color: #0000BB">$headers </span><span style="color: #007700">= </span><span style="color: #0000BB">exif_read_data</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /><br />if (!</span><span style="color: #0000BB">$headers</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">'Error: Unable to read exif headers'</span><span style="color: #007700">;<br />    exit;<br />}<br /><br /></span><span style="color: #FF8000">// Print the 'COMPUTED' headers<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">'EXIF Headers:' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br />foreach (</span><span style="color: #0000BB">$headers</span><span style="color: #007700">[</span><span style="color: #DD0000">'COMPUTED'</span><span style="color: #007700">] as </span><span style="color: #0000BB">$header </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$value</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">' %s =&gt; %s%s'</span><span style="color: #007700">, </span><span style="color: #0000BB">$header</span><span style="color: #007700">, </span><span style="color: #0000BB">$value</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Il precedente esempio visualizzerà
qualcosa simile a:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">EXIF Headers:
 Height =&gt; 576
 Width =&gt; 1024
 IsColor =&gt; 1
 ByteOrderMotorola =&gt; 0
 ApertureFNumber =&gt; f/5.6
 UserComment =&gt;
 UserCommentEncoding =&gt; UNDEFINED
 Copyright =&gt; Denis
 Thumbnail.FileType =&gt; 2
 Thumbnail.MimeType =&gt; image/jpeg</pre>
</div>
   </div>
  </div>
 </div>

 <div class="refsect1 notes" id="refsect1-function.exif-read-data-notes">
  <h3 class="title">Note</h3>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <span class="simpara">
    If <a href="ref.mbstring.php" class="link">mbstring</a> is enabled, exif will attempt to process
    the unicode and pick a charset as specified by
    <a href="exif.configuration.php#ini.exif.decode-unicode-motorola" class="link">exif.decode_unicode_motorola</a> and
    <a href="exif.configuration.php#ini.exif.decode-unicode-intel" class="link">exif.decode_unicode_intel</a>. The exif
    extension will not attempt to figure out the encoding on its own, and it is up to the user
    to properly specify the encoding for which to use for decoding by setting one of these two
    ini directives prior to calling <span class="function"><strong>exif_read_data()</strong></span>.
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <span class="simpara">
    If the <code class="parameter">file</code> is used to pass a stream to this function, then the stream
    must be seekable. Note that the file pointer position is not changed after this function returns.
   </span>
  </p></blockquote>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.exif-read-data-seealso">
  <h3 class="title">Vedere anche:</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.exif-thumbnail.php" class="function" rel="rdfs-seeAlso">exif_thumbnail()</a> - Retrieve the embedded thumbnail of an image</span></li>
   <li><span class="function"><a href="function.getimagesize.php" class="function" rel="rdfs-seeAlso">getimagesize()</a> - Get the size of an image</span></li>
   <li><a href="wrappers.php" class="xref">Supported Protocols and Wrappers</a></li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>