How to Create a File Type Validation using PHP

How to Create a File Type Validation using PHP

In this Post We Will Explain About is How to Create a File Type Validation using PHP With Example and Demo.Welcome on – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to php check file extension in upload form Example

In this post we will show you Best way to implement How to securely upload files with PHP, hear for How To Handle File Uploads With PHP with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Creating simple Form

first of all, we make simple HTML form which data contains simple file upload HTML input field.

Make a new simple file, name it Like as index.php and copy data & paste the source codes below.

<?php session_start(); ?>
<!DOCTYPE html>
	<meta charset="utf-8">
	<title>How to Make a File Type Validation using PHP</title>
	<link rel="stylesheet" type="text/css" href="pakainfo/bootstrap4/css/bootstrap.min.css">
<div class="pakainfo container">
	<h1 class="pakainfo text-center" style="margin-top:30px;">File Type Validation using PHP</h1>
	<div class="pakainfo row justify-content-center">
		<div class="col-sm-4">
					echo "
						<div class='alert alert-danger text-center'>
					echo "
						<div class='pakainfo alert alert-success text-center'>
			<div class="pakainfo card">
				<div class="card-body">
					<form method="POST" action="authorize.php" enctype="multipart/form-data">
					    <input type="file" class="form-control-file" name="file" required><br>
					    <button type="submit" class="btn btn-primary" name="authorize">Validate</button>

Making simple Validation

And then, we make simple HTML validation if simple HTML form is submitted to check data and input for the Like as a file/mime type of the PHP serever side uploaded file.

MAke a new file, name it as Serever side Like as authorize.php and copy and paste the source codes below.

 //pakainfo example
		//free type
		$permit = array('jpg', 'png', 'jpeg');
		$file = $_FILES['file']['name'];
		$ext = pathinfo($file, PATHINFO_EXTENSION);

		if(in_array($ext, $permit)){

			$_SESSION['success'] = 'Your File type permit';

			$_SESSION['custom_err'] = 'Your File type not permit';
		$_SESSION['custom_err'] = 'Please Upload a file to authorize first';
	header('location: index.php');

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example


I hope you have Got What is How to create PHP based email form with file attachment And how it works.I would Like to have FeedBack From My Blog( readers.Your Valuable FeedBack,Any Question,or any Comments about This Article( Are Most Always Welcome.

Related FAQ

Here are some more FAQ related to this Article:

  1.   MySQL SELECT all records from today using Laravel 6
  2.   ng-cut ng-copy ng-paste Events using Angular Example
  3.   Remove Last Character from String in JavaScript
  4.   Laravel 6 Delete File from public folder Example
  5.   PHP preg_match - only allow alphanumeric strings and - _ characters
  6.   Laravel Get HTTP hostname Examples Tutorial
  8.   PHP Simple Image Upload and Display Source Code
  9.   call javascript function from html
  10.   How to Make Async Requests in PHP