Tagged: php check file extension in upload form php check file extension in upload form

How to Create a File Type Validation using PHP 0

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 pakainfo.com – 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>
<html>
<head>
	<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">
</head>
<body>
<div class="pakainfo container">
	<h1 class="pakainfo text-center" style="margin-top:30px;">File Type Validation using PHP</h1>
	<hr>
	<div class="pakainfo row justify-content-center">
		<div class="col-sm-4">
			<?php
				if(isset($_SESSION['custom_err'])){
					echo "
						<div class='alert alert-danger text-center'>
							".$_SESSION['custom_err']."
						</div>
					";
 
					unset($_SESSION['custom_err']);
				}
 
				if(isset($_SESSION['success'])){
					echo "
						<div class='pakainfo alert alert-success text-center'>
							".$_SESSION['success']."
						</div>
					";
 
					unset($_SESSION['success']);
				}
 
			?>
			<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>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
</html>

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.

<?php
	session_start();
 //pakainfo example
	if(isset($_POST['authorize'])){
		//free type pakainfo.com
		$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';
		}
		else{

			$_SESSION['custom_err'] = 'Your File type not permit';
		}
	}
	else{
		$_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

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(pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(pakainfo.com) Are Most Always Welcome.