note 69083 modified in ref.pdf by bjori
| From: | bjori@php.net | Date: | Sat, 26 Aug 2006 11:23:10 +0000 |
| Subject: | note 69083 modified in ref.pdf by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-116348@lists.php.net to get a copy of this message | ||
Here is a function to test whether a file is a PDF without using any external library.
<?php
define('PDF_MAGIC', "\\x25\\x50\\x44\\x46\\x2D");
function is_pdf($filename) {
return (file_get_contents($filename, false, null, 0, strlen(PDF_MAGIC)) === PDF_MAGIC) ? true :
false;
}
?>
It's not checking if the whole file is valid, just if the correct header is present at the
beginning of the file.
--was--
Here is a function to test whether a file is a PDF without using any external library.
<?php
function is_pdf($filename) {
define('PDF_MAGIC', "\\x25\\x50\\x44\\x46\\x2D");
return (file_get_contents($filename, false, null, 0, strlen(PDF_MAGIC)) === PDF_MAGIC) ? true :
false;
}
?>
It's not checking if the whole file is valid, just if the correct header is present at the
beginning of the file.
http://php.net/manual/en/ref.pdf.php