Possible Duplicate:
How to check file types of uploaded files in PHP?
I have uploading features on my site and only PDF uploads are allowed. How can I check that the uploaded file is only a PDF? Just like getimagesize()
can verify image files.
Is there any way to check the file is a PDF? My code is below:
$whitelist = array(".pdf");
foreach ($whitelist as $item) {
if (preg_match("/$item\$/i", $_FILES['uploadfile']['name'])) {
}
else {
redirect_to("index.php");
}
}
$uploaddir = 'uploads/';
$uploadfile = mysql_prep($uploaddir . basename($_FILES['uploadfile']['name']));
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $uploadfile)) {
echo "succussfully uploaded";
}
Functions redirect_to
and mysql_prep
are defined by me. But mime type can be changed using headers. So is there any way to check the file to be an original pdf?