I need to upload the below type of file using PHP.
1-.png,
2-.jpeg
3-.jpg
4-.pdf,
5-.ppt
6-.docx and excel sheet.
I am explaining my code below.
<form name="billdata" id="billdata" enctype="multipart/form-data" method="POST" onSubmit="javascript:return checkForm();" action="complain.php">
<div style="color:#F00; text-align:center;"> <?php echo $error; ?></div>
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Upload Document :</span>
<input type="file" class="filestyle form-control" data-size="lg" name="uploadme" id="bannerimage" onChange="javascript:displayImage(event);">
</div>
</form>
complain.php:
$target_dir = "upload/";
$target_file = $target_dir . basename($imageName);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$check = getimagesize($_FILES["uploadme"]["tmp_name"]);
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") {
echo "Sorry, only JPG, JPEG, PNG files are allowed.";
$uploadOk = 0;
}
Here i can only up to image type files. Here i need all files which is given above should check and if any error is coming it will display inside the form.Please help me to resolve this issue.
You can try this.
<?php
$allowed = array('gif','png' ,'jpg');
$filename = $_FILES['uploadme']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed) ) {
echo 'error';
}
?>