I am trying to make file uploading page where docx, zip, rar, pdf, ppt these extensions only allowed to upload here I wrote code about it but its showing invalid file type error help to solve it
$allowed_types = array('zip','rar','docx','ppt');
$tmp = explode(".", $_FILES['file']['name']);
$ext = end($tmp);
$upload_dir ="uploads/assignments/";
if(isset($_FILES['file']) && $_FILES['file']['name'] !=""){
if( ($_FILES['file']['type']=="application/zip")
|| ($_FILES['file']['type']=="application/rar")
|| ($_FILES['file']['type']=="'application/docx'")
|| ($_FILES['file']['type']=="application/ppt")
&& ($_FILES['file']['size']<400000)
&& in_array($ext,$allowed_types))
Use this
$allowed = array('zip','rar','docx','ppt');//allowed types
$filename = $_FILES['file']['name'];//file name
$ext = pathinfo($filename, PATHINFO_EXTENSION);//extension checking
if(!in_array($ext,$allowed) )
{
echo 'Not Valid';
}
else
{
echo ' Valid'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With