title: Verifiy corrupted PDF using PHP
body: <p>I would like to detect corrupted PDF using PHP. I have been able to determine that on not corrupted pdf I have the tag "%%EOF" at the end of the file. I also checked for this tag on corrupted and it not appear.</p>
  
  <p>I had the idea to automatically checked the validty of my PDF file before uploading it to my server.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  $file = file('good.pdf');
  
  $endfile= $file[count($file) - 1];
  
  echo gettype($endfile),"\n";
  echo $endfile,"\n";
  
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I get this result</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>string %%EOF </code></pre>
  </div>
  </div>
  </p>
  
  <p>For now, everything seems to be fine, but I have an issue when comparing the results.</p>
  
  <p>I tested this code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  $file = file('good.pdf');
  $endfile= $file[count($file) - 1];
  $n="%%EOF";
  
  echo $endfile;
  echo $n;
  
  if ($endfile === $n) {
      echo "good";
  
  } else {
      echo "corrupted";
  }
  
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I get this result</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>%%EOF %%EOF corrupted</code></pre>
  </div>
  </div>
  </p>
  
  <p>I know that $endfile and $n are string but when i want to compare it, I never get the equality/match. I also tried with == but the result is the same.</p>
  
  <p>I also tried it like that :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  $file = file('good.pdf');
  $endfile= $file[count($file) - 1];
  $var1val = $endfile;
  $var2val = "%%EOF";
  echo $var2val;
  echo $var1val;
  $n = strcmp($var1val,$var2val); // 0 mean that they are the same
  echo $n;
  if ($n == 0) {
      echo "good";
  
  } else {
      echo "corrupted";
  }
  
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>but I get this result :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>%%EOF %%EOF 1 corrupted</code></pre>
  </div>
  </div>
  </p>
  
  <p>It gave me the same result with === .</p>
  
  <p>I only tested with a working and not corrupted pdf. Do you know why this is not working ? Maybe you have other methods using php to check if the pdf is not corrupted before I automatically upload it to my server ?</p>