$ _ FILES ["file"] ["type"] does not work with pdf, any other type such as jpg or png or csv recognizes them type pdf appears blank, I am working with php 5.6.31
Any other solution to recognize the type pdf would be very helpful, thanks
$ _ FILES ["file"] ["type"] does not work with pdf, any other type such as jpg or png or csv recognizes them type pdf appears blank, I am working with php 5.6.31
Any other solution to recognize the type pdf would be very helpful, thanks
The MIME type of a PDF is application/pdf
. Try the following:
$tipoArchivo = $_FILES["archivo"]["type"];
if (strpos($tipoArchivo, "/pdf") !== false) {
// Es un pdf
} else {
// No es pdf
}
Another thing that you have to ensure is that the file is arriving correctly. For example, it may have a greater weight than what your PHP configuration allows (in php.ini
). Look at the post_max_size
directive, whose value is 8Mb ( 8M
). If necessary, expand it. You should also look at the value of the upload_max_filesize
directive (I have it in 20M
, but I think the default value is lower). Make sure both are uncommented (without ;
in front).
The best way to see if the problem comes from the server policies is, after making sure that your pdf is correct with a pdf reader, such as the acrobat reader, check if there are any number other than 0
in $_FILES["archivo"]["error"]
.
It happened to me recently and it was because of those two directives. Make sure to restart Apache if you change them.