Sjef wrote:
Is it possible to recognize if a file for upload really is a pdf (like the function getimagesize retuns the file type of the image)?

If you have a suitible mime.magic file, and your PHP has the functionality built into it, you could try the mime_content_type() function.
http://uk.php.net/manual/en/function.mime-content-type.php


Or if not available, read the first few bytes of the file and verify that it begins with:
%PDF-1.3
(or other versions - perhaps just verify the first 4 chars.

You can do this with a simple

$fp = fopen($filename, 'rb'));
if ('%PDF' == fread($fp, 4))
  // PDF
else
  // Not PDF

This is very simple.


You could also use the "file" commandline utility if the server is a *nix machine and parse it's output.

e.g. on my machine:
[EMAIL PROTECTED] www]$ file ~/Desktop/svn-book.pdf
/home/colin/Desktop/svn-book.pdf: PDF document, version 1.3

or easier:

[EMAIL PROTECTED] www]$ file -i ~/Desktop/svn-book.pdf
/home/colin/Desktop/svn-book.pdf: application/pdf


Col.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to