How to check all type of file and display the validation message while uploading file using PHP -
i need upload below type of file using php.
1-.png, 2-.jpeg 3-.jpg 4-.pdf, 5-.ppt 6-.docx , excel sheet.
i explaining 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, jpg, jpeg, png files allowed."; $uploadok = 0; }
here can image type files. here need files given above should check , if error coming display inside form.please me resolve 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'; }
?>
Comments
Post a Comment