Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uploading docx, zip, rar, pdf, ppt, in php

Tags:

types

php

input

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))
like image 608
Imran Iqbal Avatar asked Nov 01 '22 00:11

Imran Iqbal


1 Answers

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'
}
like image 128
Abdulla Nilam Avatar answered Nov 15 '22 06:11

Abdulla Nilam